Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Alligator.Benchmark/Alligator.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@
<ProjectReference Include="..\Alligator.Solver\Alligator.Solver.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.15.8" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions Alligator.Benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Alligator.SixMaking.Model;
using Alligator.Solver;
using Alligator.Solver.Algorithms;
using BenchmarkDotNet.Running;
using System.Diagnostics;

namespace Alligator.Benchmark
Expand All @@ -10,6 +11,12 @@ class Program
{
static void Main(string[] args)
{
if (args.Contains("--benchmark"))
{
BenchmarkRunner.Run<SolverBenchmarks>();
return;
}

Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Hello Six Making Benchmark!");

Expand Down
12 changes: 12 additions & 0 deletions Alligator.Benchmark/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"profiles": {
"Diagnostic": {
"commandName": "Project",
"commandLineArgs": ""
},
"BenchmarkDotNet": {
"commandName": "Project",
"commandLineArgs": "--benchmark"
}
}
}
115 changes: 115 additions & 0 deletions Alligator.Benchmark/SolverBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
using Alligator.SixMaking.Logics;
using Alligator.SixMaking.Model;
using Alligator.Solver;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;

namespace Alligator.Benchmark
{
[MemoryDiagnoser]
[SimpleJob(RunStrategy.Monitoring, warmupCount: 1, iterationCount: 5)]
public class SolverBenchmarks
{
private SolverProvider<IPosition, Step> solverFactory = null!;
private ISolver<Step> solver = null!;
private IList<Step> example1History = null!;
private IList<Step> example2History = null!;
private IList<Step> example3History = null!;
private IList<Step> example5History = null!;

[GlobalSetup]
public void GlobalSetup()
{
var rules = new Rules(new StepPool(), new MovingRules());
var solverConfiguration = new Configuration();
solverFactory = new SolverProvider<IPosition, Step>(rules, solverConfiguration);

example1History = BuildHistory(Example1());
example2History = BuildHistory(Example2());
example3History = BuildHistory(Example3());
example5History = BuildHistory(Example5());
}

[IterationSetup]
public void IterationSetup()
{
solver = solverFactory.Create();
}

[Benchmark(Description = "Example1 - Empty board")]
public Step Example1_EmptyBoard() => solver.OptimizeNextStep(example1History);

[Benchmark(Description = "Example2 - Four pieces")]
public Step Example2_FourPieces() => solver.OptimizeNextStep(example2History);

[Benchmark(Description = "Example3 - Twelve pieces")]
public Step Example3_TwelvePieces() => solver.OptimizeNextStep(example3History);

[Benchmark(Description = "Example5 - Complex midgame")]
public Step Example5_ComplexMidgame() => solver.OptimizeNextStep(example5History);

private static IList<Step> BuildHistory(IPosition position)
{
return position.History.ToList();
}

private static IPosition Example1()
{
return new Position();
}

private static IPosition Example2()
{
IPosition position = new Position();
position.Take(new Placement(12));
position.Take(new Placement(13));
position.Take(new Placement(11));
position.Take(new Placement(17));
return position;
}

private static IPosition Example3()
{
IPosition position = new Position();
for (int i = 6; i < 18; i++)
{
position.Take(new Placement(i));
}
return position;
}

private static IPosition Example5()
{
IPosition position = new Position();
position.Take(new Placement(0));
position.Take(new Placement(12));
position.Take(new Placement(1));
position.Take(new Placement(11));
position.Take(new Placement(2));
position.Take(new Placement(17));
position.Take(new Placement(3));
position.Take(new Placement(13));
position.Take(new Placement(4));
position.Take(new Placement(10));
position.Take(new Placement(5));
position.Take(new Placement(15));
position.Take(new Placement(20));
position.Take(new Placement(16));
position.Take(new Movement(5, 10, 1));
position.Take(new Movement(15, 10, 1));
position.Take(new Placement(5));
position.Take(new Placement(6));
position.Take(new Movement(1, 6, 1));
position.Take(new Movement(12, 11, 1));
position.Take(new Movement(10, 17, 1));
position.Take(new Placement(12));
position.Take(new Placement(7));
position.Take(new Placement(22));
position.Take(new Placement(1));
position.Take(new Movement(11, 16, 2));
position.Take(new Placement(21));
position.Take(new Placement(18));
return position;
}
}
}
Loading