Skip to content

Commit

Permalink
Automatic tables in the readme with performance metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
kris701 committed Apr 10, 2024
1 parent e20e31a commit 48bdfd0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ Where:
There are some benchmark sudokus that can be found in the Benchmark folder.
Currently, the `BackTrack` solver can solve all the instances in there with a time limit of 10 seconds (though most are solved way before that).
The experiments can be run by writing `dotnet test --configuration Release`.

# Performance
| Sudokus Solved | Max Search Time (ms) | Min Search Time (ms) | Average Search Time (ms) |
| - | - | - | - |
| 5153 | 6392.02 | 0.27 | 12.84 |
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using SudokuSolver.Models;
using SudokuSolver.Solvers.BacktrackSolvers;
using ToMarkdown;

namespace SudokuSolver.Tests.Solvers.BacktrackSolvers
{
Expand All @@ -8,6 +9,17 @@ public class BacktrackSolverTests
{
public static IEnumerable<object[]> Data() => BaseTests.TestCases();

private static List<double> _searchTimes = new List<double>();
private static string _readmeFile = "../../../../README.md";
private static string _readme = "";

[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
_readme = File.ReadAllText(_readmeFile);
_readme = _readme.Substring(0, _readme.IndexOf("# Performance") + "# Performance".Length);
}

[TestMethod]
[DynamicData(nameof(Data), DynamicDataSourceType.Method)]
public void Can_Solve(string dataset, string boardStr, List<byte> boardValues)
Expand All @@ -25,6 +37,33 @@ public void Can_Solve(string dataset, string boardStr, List<byte> boardValues)
Assert.Inconclusive();
else
Assert.IsNotNull(result);
_searchTimes.Add(solver.SearchTime.TotalMilliseconds);
}

[ClassCleanup]
public static void ClassCleanup()
{
var result = new ExperimentResults();
result.Solved = _searchTimes.Count;
result.MaxTime = Math.Round(_searchTimes.Max(), 2);
result.MinTime = Math.Round(_searchTimes.Min(),2);
result.AvgTime = Math.Round(_searchTimes.Average(),2);
var text = new List<ExperimentResults>() { result }.ToMarkdownTable(new List<string>() {
"Sudokus Solved",
"Max Search Time (ms)",
"Min Search Time (ms)",
"Average Search Time (ms)"});

_readme += Environment.NewLine + text;
File.WriteAllText(_readmeFile, _readme);
}

private class ExperimentResults()
{
public int Solved { get; set; }
public double MaxTime { get; set; }
public double MinTime { get; set; }
public double AvgTime { get; set; }
}
}
}
1 change: 1 addition & 0 deletions SudokuSolver.Tests/SudokuSolver.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="ToMarkdown" Version="1.1.3" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 48bdfd0

Please sign in to comment.