private double ExecuteBenchmark() { var sw = new Stopwatch(); var currentBenchmark = benchmarksToRun[0]; Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High; for (var i = 0; i < options.Runs; i++) { GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); if (options.MemoryEfficient) { sw.Start(); currentBenchmark.Run(); sw.Stop(); } else { var oldMode = GCSettings.LatencyMode; // Make sure we can always go to the catch block, // so we can set the latency mode back to `oldMode` RuntimeHelpers.PrepareConstrainedRegions(); try { GCSettings.LatencyMode = GCLatencyMode.SustainedLowLatency; // Generation 2 garbage collection is now // deferred, except in extremely low-memory situations sw.Start(); currentBenchmark.Run(); sw.Stop(); } finally { // ALWAYS set the latency mode back GCSettings.LatencyMode = oldMode; } } GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); timings[i] = sw.ElapsedMilliseconds; sw.Reset(); } Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Normal; return(timings.Average() / BenchmarkRater.ScaleVolume(options.Threads)); }
private void RunGenericBenchmark() { var categories = new Dictionary <string, List <Result> >(); while (benchmarksToRun.Count > 0) { var currentBenchmark = benchmarksToRun[0]; lock (CurrentRunningBenchmark) { CurrentRunningBenchmark = currentBenchmark.GetName(); CurrentBenchmarkFinished = 0; } foreach (var category in currentBenchmark.GetCategories()) { if (!categories.ContainsKey(category)) { categories.Add(category, new List <Result>()); } } // Execute currentBenchmark.Initialize(); CurrentBenchmarkFinished = 0; CurrentRunningBenchmark = currentBenchmark.GetName(); var timing = ExecuteBenchmark(); currentBenchmark.Shutdown(); var result = new Result( currentBenchmark.GetName(), timing, currentBenchmark.GetRatingMethod().Invoke(timing), currentBenchmark.GetComparison(), currentBenchmark.GetRatingMethod().Invoke(currentBenchmark.GetComparison()), currentBenchmark.GetDataThroughput(timing) / BenchmarkRater.ScaleVolume(options.Threads) ); Results.Add(result); foreach (var category in currentBenchmark.GetCategories()) { categories[category].Add(result); } benchmarksToRun.RemoveAt(0); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); } ProcessCategories(categories); // Add to save foreach (var runnerResult in Results) { ResultSaver.SaveResult(options.Threads, runnerResult); } // Check for newly completed categories ResultCategoryAggregator.ProcessCategories(options, categories); }