BenchmarkDotNet icon indicating copy to clipboard operation
BenchmarkDotNet copied to clipboard

Fluent API improvements

Open ds1709 opened this issue 2 years ago • 3 comments

In my benchmark project I developed a small framework to improve fluent configuration of benchmarks. With this improvements I can configure benchmark like this

var pointHitTestJob = CreateJob();
var pointHitTestRunInfo = BenchmarkRunInfoBuilder
                .Create()
                .AddCase<SimplePointInBoundsBenchmark>(
                    pointHitTestJob,
                    caseCfg => caseCfg
                        .WithWorkload(_ => _.PointHitTest())
                        .WithGlobalSetup(_ => _.GlobalSetup())
                        .WithIterationSetup(_ => _.IterationSetup()))
                .AddCases<QuadTreePickInPointBenchmark>(
                    pointHitTestJob,
                    caseCfg => caseCfg
                        .WithWorkload(_ => _.PointHitTest())
                        .WithGlobalSetup(_ => _.GlobalSetup())
                        .WithIterationSetup(_ => _.IterationSetup())
                        .WithParameterValues(_ => _.MaxDepth, 1, 2, 3, 4, 5)
                        .WithParameterValues(_ => _.NodeSize, 256, 512, 1024))
                .Build(immutableCfg);

With this configuration method there's no need in any attributes in benchmark classes. So, if there's any sense, I can make PR to merge my developments.

ds1709 avatar Jun 21 '22 16:06 ds1709

@ds1709 thank you for your proposal! I like your idea, but I am worried that it would make our config system even more complex than it is today (attributes, command line args, custom types). @AndreyAkinshin what do you think?

adamsitnik avatar Jun 22 '22 08:06 adamsitnik

I also like the idea.

I am worried that it would make our config system even more complex than it is today (attributes, command line args, custom types)

It's a valid concern. I guess we could merge it if it doesn't introduce too many complications in the config system. @ds1709 could we check out the implementation your fluent framework somewhere? It would be nice if we can take a look on it before you start working on a proper PR.

AndreyAkinshin avatar Jul 08 '22 13:07 AndreyAkinshin

@AndreyAkinshin, sure. https://github.com/ugparu/Ugpa.QuadTree/tree/master/benchmark/Ugpa.QuadTree.Benchmark/Configuration It's small draft solution, developed for my own purposes. If it's acceptable, I can expand solution to support more scenarios.

ds1709 avatar Jul 08 '22 15:07 ds1709