/// <summary> /// run a single test. /// </summary> /// <returns>The running time, in seconds.</returns> private static double RunTest(int[] array, int type) { // timer for measuring running time Stopwatch timer = new Stopwatch(); // copy array contents to allow a repeatable test on the same data. int[] arrayCopy = new int[array.Length]; array.CopyTo(arrayCopy, 0); // select the algorithm to run switch (type) { case ARRAY: Console.Write("Array.Sort({0:N0}): ", array.Length); timer.Start(); Array.Sort(arrayCopy); timer.Stop(); break; case LSD: Console.Write("LSDRadixSort.Run({0:N0}): ", array.Length); timer.Start(); arrayCopy = LSDRadixSort.RunBinary(arrayCopy); timer.Stop(); //Console.WriteLine(Utility.ArrayContentsToString(arrayCopy)); break; case SEQUENTIAL: Console.Write("SequentialRadixTreeSort.Run({0:N0}): ", array.Length); timer.Start(); SequentialRadixTreeSort.Run(arrayCopy); timer.Stop(); break; case PARALLEL: Console.Write(" ParallelRadixTreeSort.Run({0:N0}): ", array.Length); timer.Start(); ParallelRadixTreeSort.Run(arrayCopy); timer.Stop(); break; case P_IMPROVED: Console.Write(" ParallelRadixTreeSort.RunImproved({0:N0}): ", array.Length); timer.Start(); ParallelRadixTreeSort.RunImproved(arrayCopy); timer.Stop(); break; } double time = timer.ElapsedMilliseconds / 1000.0; Console.WriteLine("{0:N3} seconds", time); return(time); }
/// <summary> /// Test the LSDRadixStringSort. /// </summary> /// <param name="wordCount">The number of words to test.</param> /// <param name="wordSize">The size of each word.</param> public static void TestLSDRadixStringSort(int wordCount, int wordSize) { string[] strings = LSDRadixSort.GetRandomStringArray(wordCount, wordSize); LSDRadixSort.RunTest(strings, wordSize); }