public static void Execution(Action<MeasureConfiguration> configurationAction) { var configuration = new MeasureConfiguration(); configurationAction(configuration); if (configuration.Action == null) throw new ArgumentException("Action should be specified"); Bench(configuration.Action, configuration.WarmUpIteration); var results = Bench(configuration.Action, configuration.Iteration); PrintResults(configuration, results); }
public static void Execution(Action <MeasureConfiguration> configurationAction) { var configuration = new MeasureConfiguration(); configurationAction(configuration); if (configuration.Action == null) { throw new ArgumentException("Action should be specified"); } Bench(configuration.Action, configuration.WarmUpIteration); var results = Bench(configuration.Action, configuration.Iteration); PrintResults(configuration, results); }
private static void PrintResults(MeasureConfiguration configuration, BenchResults results) { results.Ticks.Sort(); var min = results.Ticks.First(); var max = results.Ticks.Last(); var onePercentIndex = (int)Math.Floor((decimal)results.Ticks.Count * 1 / 100) + 1; var fivePercentIndex = (int)Math.Floor((decimal)results.Ticks.Count * 5 / 100) + 1; var medianIndex = (int)Math.Floor((decimal)results.Ticks.Count * 50 / 100) + 1; var onePercentile = results.Ticks[results.Ticks.Count - onePercentIndex]; var fivePercentile = results.Ticks[results.Ticks.Count - fivePercentIndex]; var median = results.Ticks[results.Ticks.Count - medianIndex]; lock (_lock) { if (!string.IsNullOrEmpty(configuration.Name)) { Console.WriteLine(); Console.WriteLine("[" + configuration.Name + "]"); } Console.WriteLine("{0:N0} iterations in {1:N0} ms ({2:N1} iterations/sec)", configuration.Iteration, results.Elapsed.TotalMilliseconds, configuration.Iteration / results.Elapsed.TotalSeconds); Console.WriteLine("Latencies :"); Console.WriteLine("Min : {0,10:### ### ##0}µs", min * _µsFrequency); Console.WriteLine("Avg : {0,10:### ### ##0}µs", (double)results.Elapsed.Ticks / configuration.Iteration / (TimeSpan.TicksPerMillisecond / 1000)); Console.WriteLine("Median : {0,10:### ### ##0}µs", median * _µsFrequency); Console.WriteLine("95 percentile : {0,10:### ### ##0}µs", fivePercentile * _µsFrequency); Console.WriteLine("99 percentile : {0,10:### ### ##0}µs", onePercentile * _µsFrequency); Console.WriteLine("Max : {0,10:### ### ##0}µs (Iteration #{1})", max * _µsFrequency, results.MaxIterationIndex); Console.WriteLine("G0 : {0}", results.G0Count); Console.WriteLine("G1 : {0}", results.G1Count); Console.WriteLine("G2 : {0}", results.G2Count); } }