Skip to content

Commit

Permalink
Fix benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
eduherminio committed Dec 25, 2023
1 parent 06bca9d commit 8876a67
Showing 1 changed file with 40 additions and 70 deletions.
110 changes: 40 additions & 70 deletions src/Lynx.Benchmark/GoCommandParsingAlternatives.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
/*
*
* | Method | command | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated |
* |----------- |--------------------- |----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:|
* | Sequential | go infinite | 38.06 us | 0.671 us | 0.627 us | 1.00 | 0.00 | 0.1221 | - | - | 365 B |
* | Parallell | go infinite | 16.24 us | 0.318 us | 0.504 us | 0.43 | 0.02 | 1.1597 | - | - | 2439 B |
* | | | | | | | | | | | |
* | Sequential | go in(...) d2d4 [33] | 69.36 us | 0.942 us | 0.881 us | 1.00 | 0.00 | 0.3662 | - | - | 825 B |
* | Parallell | go in(...) d2d4 [33] | 27.98 us | 1.005 us | 2.963 us | 0.40 | 0.05 | 1.3733 | - | - | 2888 B |
* | | | | | | | | | | | |
* | Sequential | go i(...) 500 [137] | 127.31 us | 2.051 us | 2.442 us | 1.00 | 0.00 | 1.2207 | - | - | 3040 B |
* | Parallell | go i(...) 500 [137] | 59.41 us | 2.109 us | 6.219 us | 0.48 | 0.05 | 2.4414 | - | - | 5096 B |
* | | | | | | | | | | | |
* | Sequential | go in(...)c 100 [66] | 90.49 us | 0.943 us | 0.882 us | 1.00 | 0.00 | 0.7324 | - | - | 1576 B |
* | Parallell | go in(...)c 100 [66] | 38.29 us | 1.494 us | 4.406 us | 0.42 | 0.05 | 1.7090 | - | - | 3632 B |
* | | | | | | | | | | | |
* | Sequential | go i(...) 500 [117] | 109.52 us | 1.283 us | 1.002 us | 1.00 | 0.00 | 1.2207 | - | - | 2776 B |
* | Parallell | go i(...) 500 [117] | 51.02 us | 1.942 us | 5.727 us | 0.48 | 0.05 | 2.3193 | - | - | 4832 B |
*
*/

using BenchmarkDotNet.Attributes;
Expand Down Expand Up @@ -87,7 +69,7 @@ public async Task CapturingGroups(string command)
[GeneratedRegex("(?<=movetime).+?(?=searchmoves|wtime|btime|winc|binc|movestogo|depth|nodes|mate|movetime|ponder|infinite|$)", RegexOptions.IgnoreCase | RegexOptions.Compiled, "es-ES")]
private static partial Regex MoveTimeRegex();

[GeneratedRegex(@"(?<searchmoves>(?<=searchmoves\s+)\w+)|(?<wtime>(?<=wtime\s+)\d+)|(?<btime>(?<=btime\s+)\d+)|(?<winc>(?<=winc\s+)\d+)|(?<binc>(?<=binc\s+)\d+)|(?<depth>(?<=depth\s+)\d+)|(?<movestogo>(?<=movestogo\s+)\d+)|(?<nodes>(?<=nodes\s+)\d+)|(?<movetime>(?<=movetime\s+)\d+)|(?<mate>(?<=mate\s+)\d+)|(?<infinite>infinite)|(?<ponder>ponder)|(?<infinite>infinite)|(?<mate>mate)")]
[GeneratedRegex(@"(?<wtime>(?<=wtime\s+)\d+)|(?<btime>(?<=btime\s+)\d+)|(?<winc>(?<=winc\s+)\d+)|(?<binc>(?<=binc\s+)\d+)|(?<movestogo>(?<=movestogo\s+)\d+)|(?<depth>(?<=depth\s+)\d+)|(?<movetime>(?<=movetime\s+)\d+)|(?<infinite>infinite)|(?<ponder>ponder)")]
private static partial Regex CapturingGroups();

public List<string> SearchMoves { get; private set; } = default!;
Expand Down Expand Up @@ -267,59 +249,47 @@ private async Task ParseInParallel(string command)

private void ParseRegexCapturingGroups(string command)
{
var groups = CapturingGroups().Match(command).Groups;

if (groups["wtime"].Success && int.TryParse(groups["wtime"].ValueSpan, out var value))
{
WhiteTime = value;
}

if (groups["btime"].Success && int.TryParse(groups["btime"].ValueSpan, out value))
{
BlackTime = value;
}

if (groups["winc"].Success && int.TryParse(groups["winc"].ValueSpan, out value))
{
WhiteIncrement = value;
}

if (groups["binc"].Success && int.TryParse(groups["binc"].ValueSpan, out value))
{
BlackIncrement = value;
}

if (groups["movestogo"].Success && int.TryParse(groups["movestogo"].ValueSpan, out value))
{
MovesToGo = value;
}

if (groups["depth"].Success && int.TryParse(groups["depth"].ValueSpan, out value))
foreach (var match in CapturingGroups().Matches(command).Cast<Match>())
{
Depth = value;
}

if (groups["nodes"].Success && int.TryParse(groups["nodes"].ValueSpan, out value))
{
Nodes = value;
}

if (groups["mate"].Success && int.TryParse(groups["mate"].ValueSpan, out value))
{
Mate = value;
}

if (groups["movetime"].Success && int.TryParse(groups["movetime"].ValueSpan, out value))
{
MoveTime = value;
}
for (int i = 1; i < match.Groups.Count; ++i)
{
var group = match.Groups[i];
if (group.Success)
{
switch (group.Name)
{
case "wtime":
WhiteTime = int.Parse(group.Value);
break;
case "btime":
BlackTime = int.Parse(group.Value);
break;
case "winc":
WhiteIncrement = int.Parse(group.Value);
break;
case "binc":
BlackIncrement = int.Parse(group.Value);
break;
case "movestogo":
MovesToGo = int.Parse(group.Value);
break;
case "infinite":
Infinite = true;
break;
case "ponder":
Ponder = true;
break;
case "depth":
Depth = int.Parse(group.Value);
break;
case "movetime":
MoveTime = int.Parse(group.Value);
break;
}

if (groups["searchmoves"].Success)
{
SearchMoves = groups["searchmoves"].Value.Split(' ', StringSplitOptions.RemoveEmptyEntries).ToList();
break;
}
}
}

Infinite = groups["infinite"].Success;
Ponder = groups["ponder"].Success;
}
}

0 comments on commit 8876a67

Please sign in to comment.