From bbbdd097a2063c4c8bec5d913e26e9fcdc8408bf Mon Sep 17 00:00:00 2001
From: Xian55 <367101+Xian55@users.noreply.github.com>
Date: Sun, 8 Sep 2024 12:16:11 +0200
Subject: [PATCH] .gitignore BenchmarkDotNet artifacts
Added new project Benchmarks
Benchmarks: Added two bench
---
.gitignore | 5 +-
Benchmarks/Benchmarks.csproj | 18 +++
Benchmarks/PPather/PPatherHasHoles.cs | 74 +++++++++++
Benchmarks/Program.cs | 5 +
...CoreRequirementCreateTargetCastingSpell.cs | 120 ++++++++++++++++++
MasterOfPuppets.sln | 14 ++
6 files changed, 235 insertions(+), 1 deletion(-)
create mode 100644 Benchmarks/Benchmarks.csproj
create mode 100644 Benchmarks/PPather/PPatherHasHoles.cs
create mode 100644 Benchmarks/Program.cs
create mode 100644 Benchmarks/Requirement/CoreRequirementCreateTargetCastingSpell.cs
diff --git a/.gitignore b/.gitignore
index 00a5e8d6f..5373377e8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -293,4 +293,7 @@ HeadlessServer/data_config.json
PathingAPI/frame_config.json
PathingAPI/addon_config.json
-PathingAPI/data_config.json
\ No newline at end of file
+PathingAPI/data_config.json
+
+# BenchmarkDotNet artifacts
+**/BenchmarkDotNet.Artifacts/
\ No newline at end of file
diff --git a/Benchmarks/Benchmarks.csproj b/Benchmarks/Benchmarks.csproj
new file mode 100644
index 000000000..b36f521ad
--- /dev/null
+++ b/Benchmarks/Benchmarks.csproj
@@ -0,0 +1,18 @@
+
+
+
+ Exe
+ enable
+ enable
+ true
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Benchmarks/PPather/PPatherHasHoles.cs b/Benchmarks/PPather/PPatherHasHoles.cs
new file mode 100644
index 000000000..89e8b8df1
--- /dev/null
+++ b/Benchmarks/PPather/PPatherHasHoles.cs
@@ -0,0 +1,74 @@
+using BenchmarkDotNet.Attributes;
+
+namespace Benchmarks.PPather;
+
+[MemoryDiagnoser]
+public class PPatherHasHoles
+{
+
+ public bool hasholes = true;
+
+ public readonly uint holes;
+
+ // 0 ..3, 0 ..3
+ private static readonly int[] old_holetab_h = [0x1111, 0x2222, 0x4444, 0x8888];
+ private static readonly int[] old_holetab_v = [0x000F, 0x00F0, 0x0F00, 0xF000];
+
+ private static readonly int[] new_holetab = [
+ 0x1111 & 0x000F, 0x1111 & 0x00F0, 0x1111 & 0x0F00, 0x1111 & 0xF000,
+ 0x2222 & 0x000F, 0x2222 & 0x00F0, 0x2222 & 0x0F00, 0x2222 & 0xF000,
+ 0x4444 & 0x000F, 0x4444 & 0x00F0, 0x4444 & 0x0F00, 0x4444 & 0xF000,
+ 0x8888 & 0x000F, 0x8888 & 0x00F0, 0x8888 & 0x0F00, 0x8888 & 0xF000
+ ];
+
+ [Benchmark(Baseline = true)]
+ [ArgumentsSource(nameof(Inputs_Fast))]
+ public bool IsHole_Old(int i, int j)
+ {
+ if (!hasholes)
+ return false;
+
+ i /= 2;
+ j /= 2;
+
+ return i <= 3 && j <= 3 && (holes & old_holetab_h[i] & old_holetab_v[j]) != 0;
+ }
+
+ [Benchmark]
+ [ArgumentsSource(nameof(Inputs_Fast))]
+ public bool IsHole_New(int i, int j)
+ {
+ if (!hasholes)
+ return false;
+
+ i >>= 1;
+ j >>= 1;
+
+ if (i > 3 || j > 3)
+ return false;
+
+ int index = (i << 2) | j;
+
+ return (holes & new_holetab[index]) != 0;
+ }
+
+ public static IEnumerable