I'm benchmarking some .net framework stuffs, I'm using .net framework, C# and BenchmarkDotNet
What I want to do is; I'm writing a lot of benchmark tests and I'm only interested in summary sections of the reports. How can I configure BenchmarkDotNet to show only summary section of tests?
Here is a screenshot to be more clear;
Why do you want skip logs? Benchmarks could take a lot of time, if you disable logs, you will look at the black screen for some time. If something goes wrong, then you will not know about it.
However, there is a workaround. BenchmarkDotNet uses special Configs for customization. Loggers
are a part of these Configs. If you don't specify any config, the default one will be using it. You can easily extend it, but there is no nice API to disable a part of the default config (hopefully, will be added soon; the corresponded API is in the discussion stage right now). So, you have to define own config, add all parts of the default config except loggers and pass it to BenchmarkRunner
. Then the ConsoleLogger
will not be used. After that, you have to print the summary table and conclusions to console manually. Also, the full log and the summary table in markdown format will be in the BenchmarkDotNet.Artifacts
folder.
The source code:
var config = new ManualConfig();
config.Add(DefaultConfig.Instance.GetColumnProviders().ToArray());
config.Add(DefaultConfig.Instance.GetExporters().ToArray());
config.Add(DefaultConfig.Instance.GetDiagnosers().ToArray());
config.Add(DefaultConfig.Instance.GetAnalysers().ToArray());
config.Add(DefaultConfig.Instance.GetJobs().ToArray());
config.Add(DefaultConfig.Instance.GetValidators().ToArray());
config.UnionRule = ConfigUnionRule.AlwaysUseGlobal; // Overriding the default
var summary = BenchmarkRunner.Run<TestBench>(config);
var logger = ConsoleLogger.Default;
MarkdownExporter.Console.ExportToLog(summary, logger);
ConclusionHelper.Print(logger, config.GetCompositeAnalyser().Analyse(summary).ToList());
AndreyAkinshin answeser is really great, but one part isnt valid anymore! ManualConfig doesnt provide .GetCompositeAnalyser() anymore, so you have to get the ImmutableConfig and thats only possible to form the BenchmarksCase
For example if you are only running one Benchmarkcase: you can do this with ...First()
this fixed it for me
ConclusionHelper.Print(logger, summary.BenchmarksCases.**First()**.Config.GetCompositeAnalyser().Analyse(summary).ToList());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With