public static void TestList(ListAggregation a, long[] vals, string msg) { long bestTimeMillis = int.MaxValue; const int NRUNS = 10; IEnumerable <long> it = null; int threadsUsed = int.MaxValue; for (int i = 0; i < NRUNS; ++i) { WorkerThreadReport.SetRefTime(); Stopwatch sw = Stopwatch.StartNew(); it = a(vals, vals.Length); sw.Stop(); if (sw.ElapsedMilliseconds < bestTimeMillis) { bestTimeMillis = sw.ElapsedMilliseconds; } int used = WorkerThreadReport.UsedThreads; if (used < threadsUsed) { threadsUsed = used; } } Console.WriteLine("{0}: total primes is {1}, done in {2} ms!", msg, it.Count(), bestTimeMillis); Console.WriteLine("{0} threads were used!", threadsUsed); }
private static void StatsInit() { WorkUnits = 0; WorkerThreadReport.SetRefTime(); }