Skip to content

Commit

Permalink
Add Offset_Benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
eduherminio committed Jan 10, 2024
1 parent 828139f commit 654e270
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/Lynx.Benchmark/Offset_Benchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
*
*
*
*/

using BenchmarkDotNet.Attributes;
using Lynx.Model;
using System.Runtime.CompilerServices;

namespace Lynx.Benchmark;

file static class Utils
{
public static readonly int[] PieceOffsetArray = [0, 6];

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int PieceOffset(int side)
{
return 6 - (6 * side);
}
}

public class Offset_Benchmark : BaseBenchmark
{
[Params(1, 10, 100, 1_000, 10_000)]
public int Size { get; set; }

[Benchmark(Baseline = true)]
public int Calculated()
{
int count = 0;

for (int i = 0; i < Size; ++i)
{
count += Utils.PieceOffset((int)Side.White) + Utils.PieceOffset((int)Side.Black);
}

return count;
}

[Benchmark]
public int Array()
{
int count = 0;

for (int i = 0; i < Size; ++i)
{
count += Utils.PieceOffsetArray[(int)Side.White] + Utils.PieceOffsetArray[(int)Side.Black];
}

return count;
}
}

0 comments on commit 654e270

Please sign in to comment.