static void SingleTest(int denominator) { FrequencyArray time_freq = new FrequencyArray(); FrequencyArray loop_freq = new FrequencyArray(); DoTest(denominator, time_freq, loop_freq); time_freq.Sort(); loop_freq.Sort(); ShowResults(time_freq, "Time taken to convert floating point to faction (time is in 10s of nanoseconds)", "Time"); #if CALCULATE_LOOP_STATISTICS ShowResults(loop_freq, "Iterations taken to convert floating point to faction", "Loops"); #else Console.WriteLine("\nStatistics for loop count not gathered. To enable loop statistics,\n"); Console.WriteLine("recompile defining \"CALCULATE_LOOP_STATISTICS\"\n"); #endif }
static void RandomTest(int minTests) { Random rnd = new Random(); ArrayList denominators = new ArrayList(); int nTests = 0; while (nTests < minTests) { int denominator = rnd.Next(minTests, 214748364) % minTests; // Make sure it's a unique denominator bool found = false; foreach (int dem in denominators) { if (dem == denominator) { found = true; break; } } if (!found) { denominators.Add(denominator); nTests += denominator - 1; } } FrequencyArray time_freq = new FrequencyArray(); FrequencyArray loop_freq = new FrequencyArray(); foreach (int denominator in denominators) { DoTest(denominator, time_freq, loop_freq); } time_freq.Sort(); loop_freq.Sort(); ShowResults(time_freq, "Time taken to convert floating point to faction (time is in 10s of nanoseconds)", "Time"); #if CALCULATE_LOOP_STATISTICS ShowResults(loop_freq, "Iterations taken to convert floating point to faction", "Loops"); #else Console.WriteLine("\nStatistics for loop count not gathered. To enable loop statistics,\n"); Console.WriteLine("recompile defining \"CALCULATE_LOOP_STATISTICS\"\n"); #endif }