Skip to content

Commit f229c77

Browse files
committed
Fix BenchmarkDotNet: fresh solver per iteration via IterationSetup + RunStrategy.Monitoring
Previous run measured cached TT lookups (microseconds). Now measures real cold search (milliseconds). Baseline results on main: Example1 (empty board): 146ms, 178 MB allocated Example2 (four pieces): 176ms, 176 MB allocated Example3 (twelve pieces): 1300ms, 1630 MB allocated Example5 (complex midgame):13892ms, 15907 MB allocated Key finding: GC pressure is the dominant bottleneck (1.28M Gen0 collections for Example5).
1 parent b250c4a commit f229c77

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"profiles": {
3+
"Diagnostic": {
4+
"commandName": "Project",
5+
"commandLineArgs": ""
6+
},
7+
"BenchmarkDotNet": {
8+
"commandName": "Project",
9+
"commandLineArgs": "--benchmark"
10+
}
11+
}
12+
}

Alligator.Benchmark/SolverBenchmarks.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,40 @@
22
using Alligator.SixMaking.Model;
33
using Alligator.Solver;
44
using BenchmarkDotNet.Attributes;
5+
using BenchmarkDotNet.Engines;
56

67
namespace Alligator.Benchmark
78
{
89
[MemoryDiagnoser]
9-
[SimpleJob(warmupCount: 1, iterationCount: 5)]
10+
[SimpleJob(RunStrategy.Monitoring, warmupCount: 1, iterationCount: 5)]
1011
public class SolverBenchmarks
1112
{
13+
private SolverProvider<IPosition, Step> solverFactory = null!;
1214
private ISolver<Step> solver = null!;
1315
private IList<Step> example1History = null!;
1416
private IList<Step> example2History = null!;
1517
private IList<Step> example3History = null!;
1618
private IList<Step> example5History = null!;
1719

1820
[GlobalSetup]
19-
public void Setup()
21+
public void GlobalSetup()
2022
{
2123
var rules = new Rules(new StepPool(), new MovingRules());
2224
var solverConfiguration = new Configuration();
23-
var solverFactory = new SolverProvider<IPosition, Step>(rules, solverConfiguration);
24-
solver = solverFactory.Create();
25+
solverFactory = new SolverProvider<IPosition, Step>(rules, solverConfiguration);
2526

2627
example1History = BuildHistory(Example1());
2728
example2History = BuildHistory(Example2());
2829
example3History = BuildHistory(Example3());
2930
example5History = BuildHistory(Example5());
3031
}
3132

33+
[IterationSetup]
34+
public void IterationSetup()
35+
{
36+
solver = solverFactory.Create();
37+
}
38+
3239
[Benchmark(Description = "Example1 - Empty board")]
3340
public Step Example1_EmptyBoard() => solver.OptimizeNextStep(example1History);
3441

0 commit comments

Comments
 (0)