Пример #1
0
        public void RunXY(XyTestSettings settings)
        {
            TimeSpan monotonicTimes = TimeSpan.Zero;
            TimeSpan introTimes     = TimeSpan.Zero;

            Console.WriteLine($"Running a sequence of {settings.Count} with input size: {settings.SizeX * settings.SizeY}.");

            XyObject[] elements   = new XyObject[settings.SizeX * settings.SizeY];
            Random     randomizer = new Random();

            for (int t = 0; t < settings.Count; t++)
            {
                Console.WriteLine($"Starting test #{t + 1}.");
                Console.WriteLine($"Randomizing {settings.SizeX * settings.SizeY} items.");
                long startMemory = GC.GetTotalMemory(false);
                int  xyIndex     = 0;
                for (int j = 0; j < settings.SizeX; j++)
                {
                    int currentRandomValueX = randomizer.Next(settings.MaxValue);
                    for (int k = 0; k < settings.SizeY; k++)
                    {
                        int      currentRandomValueY = randomizer.Next(settings.MaxValue);
                        XyObject currentValue        = new XyObject((float)currentRandomValueX / 9, (float)currentRandomValueY / 9);
                        elements[xyIndex++] = currentValue;
                    }
                }

                long consumedMemory = GC.GetTotalMemory(false) - startMemory;
                Console.WriteLine($"Memory consumed by input array: {consumedMemory} bytes.");
                monotonicTimes += runMethod("monotonic-sort", (array) =>
                {
                    MonotonicSorter mfSort = new MonotonicSorter();
                    mfSort.Sort(array, settings.Radix);
                }, elements);
                introTimes += runMethod("built-in intro-sort", (array) =>
                {
                    Array.Sort(array);
                }, elements);
            }

            Console.WriteLine($"Results for data sets of size: {settings.SizeX * settings.SizeY}");
            Console.WriteLine($"The average monotonic sort took: {monotonicTimes.TotalMilliseconds / settings.Count} ms.");
            Console.WriteLine($"The average built-in intro-sort took: {introTimes.TotalMilliseconds / settings.Count} ms.");
            Console.WriteLine($"Time ratio: introsort/monotonic-sort: {introTimes.TotalMilliseconds / monotonicTimes.TotalMilliseconds}");
        }
Пример #2
0
        public XyTestSettings LoadXySettings()
        {
            Console.ForegroundColor = ConsoleColor.White;
            int sizeX      = loadValue("Please enter the X set size:", 1000);
            int sizeY      = loadValue("Please enter the Y set size (optional):", sizeX);
            int testNumber = loadValue("Please enter the tests number:", 1);

            int       mode = loadValue("Please select Radix sort (1 - LSD; 2 - MSD):", 2);
            RadixType radix;

            if (mode == 1)
            {
                Console.WriteLine("Using LSD Radix sort.");
                radix = RadixType.LSD;
            }
            else if (mode == 2)
            {
                Console.WriteLine("Using MSD Radix sort.");
                radix = RadixType.MSD;
            }
            else
            {
                Console.WriteLine("Using MSD Radix sort (default).");
                radix = RadixType.MSD;
            }

            int maxValue = int.MaxValue;

            if (radix == RadixType.LSD)
            {
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.WriteLine("The monotonic-sort implementation boosts performance by comparing only the relevant bytes of the monotonic values.");
                Console.WriteLine("e.g.: If the maximal monotonic value binary representation does not use the left-most byte, none of the other monotonic value uses it and it can be skipped.");
                Console.WriteLine("This feature is applicable only to non-negative monotonic values.");
                Console.ForegroundColor = ConsoleColor.White;
                maxValue = loadValue("Please enter maximal possible value (optional):");
            }

            XyTestSettings res = new XyTestSettings(sizeX, sizeY, testNumber, maxValue, radix);

            return(res);
        }