public static BenchmarkComparison[] StartAndCompare(Action baseline, BenchmarkParameters parameters, params Action[] actions) { var mainResult = Start(baseline, parameters); var otherResults = StartMultiple(actions, parameters); return(Compare(mainResult, otherResults)); }
public static BenchmarkResult Start(Action actionToProfile, BenchmarkParameters parameters) { PerformWarmup(actionToProfile, parameters); var result = new BenchmarkResult(actionToProfile.Method.Name); var iterations = parameters.BenchmarkIterations; using (var benchmark = StartScope(result)) { for (var i = 0; i < iterations; i++) { /* TODO: * I had to call Invoke on the passed action. This is a virtual call, * that is slower. Find a way to get rid of it. */ actionToProfile.Invoke(); } } result.AverageMilliseconds /= iterations; result.AverageTicks /= iterations; return(result); }
public static BenchmarkResult[] StartMultiple(Action[] actionsToProfile, BenchmarkParameters parameters) { var results = new BenchmarkResult[actionsToProfile.Length]; for (var i = 0; i < actionsToProfile.Length; i++) { results[i] = Start(actionsToProfile[i], parameters); } return(results); }
private static void PerformWarmup(Action actionToProfile, BenchmarkParameters parameters) { // Do a warm-up spin if warmup is enabled if (!parameters.PerformWarmup) { return; } parameters.InitializeAction?.Invoke(); for (long i = 0; i < parameters.WarmupIterations; i++) { actionToProfile.Invoke(); } }