Exemplo n.º 1
0
        public static void TestIntMaxMinFunctions(int testSetSize)
        {
            WriteLine();
            Write($"Testing int min/max functions, generating test data...");
            var testData = GetRandomIntArray(testSetSize);

            WriteLine($" done, testing...");

            var naiveTimesMs = new List <long>();
            var hwTimesMs    = new List <long>();

            for (var i = 0; i < 3; i++)
            {
                int min, max;
                stopwatch.Restart();
                IntSimdProcessor.NaiveMinMax(testData, out min, out max);
                var naiveTimeMs = stopwatch.ElapsedMilliseconds;
                naiveTimesMs.Add(naiveTimeMs);
                WriteLine($"Naive analysis took:                {naiveTimesMs.Average():.##}ms (min: {min}, max: {max}).");

                stopwatch.Restart();
                IntSimdProcessor.HWAcceleratedMinMax(testData, out min, out max);
                var hwTimeMs = stopwatch.ElapsedMilliseconds;
                hwTimesMs.Add(hwTimeMs);
                WriteLine($"Hareware accelerated analysis took: {hwTimesMs.Average():.##}ms (min: {min}, max: {max}).");
            }

            WriteLine("Finding min & max of ints");
            WriteLine($"Naive method average time:          {naiveTimesMs.Average()}");
            WriteLine($"HW accelerated method average time: {hwTimesMs.Average()}");
            WriteLine($"Hardware speedup:                   {naiveTimesMs.Average() / hwTimesMs.Average():P}%");
        }
Exemplo n.º 2
0
        public static void TestIntArrayAdditionFunctions(int testSetSize)
        {
            WriteLine();
            Write("Testing int array addition, generating test data...");
            var intsOne = GetRandomIntArray(testSetSize);
            var intsTwo = GetRandomIntArray(testSetSize);

            WriteLine($" done, testing...");

            var naiveTimesMs = new List <long>();
            var hwTimesMs    = new List <long>();

            for (var i = 0; i < 3; i++)
            {
                stopwatch.Restart();
                var result      = IntSimdProcessor.NaiveSumFunc(intsOne, intsTwo);
                var naiveTimeMs = stopwatch.ElapsedMilliseconds;
                naiveTimesMs.Add(naiveTimeMs);
                WriteLine($"Naive analysis took:                {naiveTimeMs}ms (last value = {result.Last()}).");

                stopwatch.Restart();
                result = IntSimdProcessor.HWAcceleratedSumFunc(intsOne, intsTwo);
                var hwTimeMs = stopwatch.ElapsedMilliseconds;
                hwTimesMs.Add(hwTimeMs);
                WriteLine($"Hareware accelerated analysis took: {hwTimeMs}ms (last value = {result.Last()}).");
            }

            WriteLine("Int array addition:");
            WriteLine($"Naive method average time:          {naiveTimesMs.Average():.##}");
            WriteLine($"HW accelerated method average time: {hwTimesMs.Average():.##}");
            WriteLine($"Hardware speedup:                   {naiveTimesMs.Average() / hwTimesMs.Average():P}%");
        }
Exemplo n.º 3
0
        public static void TestInPlaceIntAddition(int testSetSize)
        {
            WriteLine();
            Write("Testing int array in place addition, generating test data...");
            var ushortsOne = GetRandomIntArray(testSetSize);
            var ushortsTwo = GetRandomIntArray(testSetSize);

            WriteLine(" done, testing...");

            var naiveTimesMs = new List <long>();
            var hwTimesMs    = new List <long>();

            for (var i = 0; i < 3; i++)
            {
                var ushortsOneCopy = new int[ushortsOne.Length];

                ushortsOne.CopyTo(ushortsOneCopy, 0);
                stopwatch.Restart();
                IntSimdProcessor.HwAcceleratedSumInPlace(ushortsOneCopy, ushortsTwo);
                var hwTimeMs = stopwatch.ElapsedMilliseconds;
                hwTimesMs.Add(hwTimeMs);
                WriteLine($"HW accelerated addition took: {hwTimeMs}ms (last value = {ushortsOneCopy[ushortsOneCopy.Length - 1]}).");

                ushortsOne.CopyTo(ushortsOneCopy, 0);
                stopwatch.Restart();
                IntSimdProcessor.NaiveSumInPlace(ushortsOneCopy, ushortsTwo);
                var naiveTimeMs = stopwatch.ElapsedMilliseconds;
                naiveTimesMs.Add(naiveTimeMs);
                WriteLine($"Naive addition took:          {naiveTimeMs}ms (last value = {ushortsOneCopy[ushortsOneCopy.Length - 1]}).");
            }

            WriteLine("Testing int array addition in place");
            WriteLine($"Naive method average time:          {naiveTimesMs.Average():.##}");
            WriteLine($"HW accelerated method average time: {hwTimesMs.Average():.##}");
            WriteLine($"Hardware speedup:                   {naiveTimesMs.Average() / hwTimesMs.Average():P}%");
        }