-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
828139f
commit 654e270
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |