static void Main(string[] args) { var switcher = new BenchmarkSwitcher(new[] { typeof(LeadingZeroCount.LeadingZeroCount64BitBenchmark), typeof(LeadingZeroCount.LeadingZeroCount32BitBenchmark), typeof(Recording.Recording32BitBenchmark), }); switcher.Run(args); }
static void Main(string[] args) { // Use reflection for a more maintainable way of creating the benchmark switcher, // Benchmarks are listed in namespace order first (e.g. BenchmarkDotNet.Samples.CPU, // BenchmarkDotNet.Samples.IL, etc) then by name, so the output is easy to understand var benchmarks = typeof(Program).Assembly().GetTypes() .Where(t => t.GetMethods(BindingFlags.Instance | BindingFlags.Public) .Any(m => m.GetCustomAttributes(typeof(BenchmarkAttribute), false).Any())) .OrderBy(t => t.Namespace) .ThenBy(t => t.Name) .ToArray(); var benchmarkSwitcher = new BenchmarkSwitcher(benchmarks); benchmarkSwitcher.Run(args); }
public void CmdLineParsingTest() { // Don't cover every combination, just pick a complex scenarion and check // it works end-to-end, i.e. "method=Method1" and "class=ClassB" var types = new[] { typeof(ClassA), typeof(ClassB), typeof(ClassC), typeof(NOTIntegrationTests.ClassD) }; var switcher = new BenchmarkSwitcher(types); // BenchmarkSwitcher only picks up config values via the args passed in, not via class annotations (e.g "[DryConfig]") var results = switcher.Run(new[] { "job=Dry", "class=ClassA,ClassC", "methods=Method4" }); Assert.Equal(2, results.Count()); Assert.Equal(3, results.SelectMany(r => r.Benchmarks).Count()); Assert.True(results.Any(r => r.Benchmarks.Any(b => b.Target.Type.Name == "ClassA" && b.Target.Method.Name == "Method1"))); Assert.True(results.Any(r => r.Benchmarks.Any(b => b.Target.Type.Name == "ClassA" && b.Target.Method.Name == "Method2"))); Assert.True(results.Any(r => r.Benchmarks.Any(b => b.Target.Type.Name == "ClassB" && b.Target.Method.Name == "Method4"))); }