From 38552cd1d462f6af6fc10b5656eca02fa9c9f3af Mon Sep 17 00:00:00 2001 From: Martin Evans Date: Mon, 29 Apr 2024 16:04:37 +0100 Subject: [PATCH 1/2] - Updated Myriad.ECS to 9.1.0 - Added Vectorised (SIMD) query implementations --- .../Ecs.CSharp.Benchmark.csproj | 2 +- .../SystemWithOneComponent/Myriad.cs | 24 +++++++++++++++++++ .../SystemWithTwoComponents/Myriad.cs | 22 +++++++++++++++++ .../Myriad.cs | 22 +++++++++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) diff --git a/source/Ecs.CSharp.Benchmark/Ecs.CSharp.Benchmark.csproj b/source/Ecs.CSharp.Benchmark/Ecs.CSharp.Benchmark.csproj index d7dfa4e..5977868 100644 --- a/source/Ecs.CSharp.Benchmark/Ecs.CSharp.Benchmark.csproj +++ b/source/Ecs.CSharp.Benchmark/Ecs.CSharp.Benchmark.csproj @@ -18,7 +18,7 @@ - + diff --git a/source/Ecs.CSharp.Benchmark/SystemWithOneComponent/Myriad.cs b/source/Ecs.CSharp.Benchmark/SystemWithOneComponent/Myriad.cs index a19a3bb..5cf5737 100644 --- a/source/Ecs.CSharp.Benchmark/SystemWithOneComponent/Myriad.cs +++ b/source/Ecs.CSharp.Benchmark/SystemWithOneComponent/Myriad.cs @@ -1,4 +1,5 @@ using System; +using System.Numerics; using BenchmarkDotNet.Attributes; using Ecs.CSharp.Benchmark.Contexts; using Ecs.CSharp.Benchmark.Contexts.Myriad_Components; @@ -29,6 +30,20 @@ public void Execute(ReadOnlySpan e, Span t0) } } + private struct MyriadVectorForEach1 + : IVectorChunkQuery1 + { + private static readonly Vector _one = Vector.One; + + public void Execute(Span> t0, int padding) + { + for (int i = 0; i < t0.Length; i++) + { + t0[i] += _one; + } + } + } + private sealed class MyriadContext : MyriadBaseContext { public MyriadContext(int entityCount, int padding) @@ -108,5 +123,14 @@ public void Myriad_Delegate() c.Value++; }); } + + [BenchmarkCategory(Categories.Myriad)] + [Benchmark] + public void Myriad_SingleThreadChunk_SIMD() + { + World world = _myriad.World; + + world.ExecuteVectorChunk(new MyriadVectorForEach1()); + } } } diff --git a/source/Ecs.CSharp.Benchmark/SystemWithTwoComponents/Myriad.cs b/source/Ecs.CSharp.Benchmark/SystemWithTwoComponents/Myriad.cs index 3debe73..951acdc 100644 --- a/source/Ecs.CSharp.Benchmark/SystemWithTwoComponents/Myriad.cs +++ b/source/Ecs.CSharp.Benchmark/SystemWithTwoComponents/Myriad.cs @@ -1,4 +1,5 @@ using System; +using System.Numerics; using BenchmarkDotNet.Attributes; using Ecs.CSharp.Benchmark.Contexts; using Ecs.CSharp.Benchmark.Contexts.Myriad_Components; @@ -29,6 +30,18 @@ public void Execute(ReadOnlySpan e, Span t0, Span + { + public void Execute(Span> t0, Span> t1, int padding) + { + for (int i = 0; i < t0.Length; i++) + { + t0[i] += t1[i]; + } + } + } + private sealed class MyriadContext : MyriadBaseContext { public MyriadContext(int entityCount, int padding) @@ -108,5 +121,14 @@ public void Myriad_Delegate() c1.Value += c2.Value; }); } + + [BenchmarkCategory(Categories.Myriad)] + [Benchmark] + public void Myriad_SingleThreadChunk_SIMD() + { + World world = _myriad.World; + + world.ExecuteVectorChunk(new MyriadVectorForEach2()); + } } } diff --git a/source/Ecs.CSharp.Benchmark/SystemWithTwoComponentsMultipleComposition/Myriad.cs b/source/Ecs.CSharp.Benchmark/SystemWithTwoComponentsMultipleComposition/Myriad.cs index d50fe00..85fa93a 100644 --- a/source/Ecs.CSharp.Benchmark/SystemWithTwoComponentsMultipleComposition/Myriad.cs +++ b/source/Ecs.CSharp.Benchmark/SystemWithTwoComponentsMultipleComposition/Myriad.cs @@ -1,4 +1,5 @@ using System; +using System.Numerics; using BenchmarkDotNet.Attributes; using Ecs.CSharp.Benchmark.Contexts; using Ecs.CSharp.Benchmark.Contexts.Myriad_Components; @@ -29,6 +30,18 @@ public void Execute(ReadOnlySpan e, Span t0, Span + { + public void Execute(Span> t0, Span> t1, int padding) + { + for (int i = 0; i < t0.Length; i++) + { + t0[i] += t1[i]; + } + } + } + private sealed class MyriadContext : MyriadBaseContext { public MyriadContext(int entityCount) @@ -121,5 +134,14 @@ public void Myriad_Delegate() c1.Value += c2.Value; }); } + + [BenchmarkCategory(Categories.Myriad)] + [Benchmark] + public void Myriad_SingleThreadChunk_SIMD() + { + World world = _myriad.World; + + world.ExecuteVectorChunk(new MyriadVectorForEach2()); + } } } From 9c2aba8ce5aa1c4b83d73ef3862784c543ed7a5f Mon Sep 17 00:00:00 2001 From: Martin Evans Date: Thu, 18 Jul 2024 14:19:46 +0100 Subject: [PATCH 2/2] Minimum changes required to generate table sorted by time --- source/Ecs.CSharp.Benchmark/Program.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/Ecs.CSharp.Benchmark/Program.cs b/source/Ecs.CSharp.Benchmark/Program.cs index 1e9cb5a..905e7d6 100644 --- a/source/Ecs.CSharp.Benchmark/Program.cs +++ b/source/Ecs.CSharp.Benchmark/Program.cs @@ -2,6 +2,7 @@ using System.Globalization; using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Order; using BenchmarkDotNet.Running; using Ecs.CSharp.Benchmark; @@ -25,7 +26,9 @@ typeof(SystemWithTwoComponentsMultipleComposition) }); -IConfig configuration = DefaultConfig.Instance.WithOptions(ConfigOptions.DisableOptimizationsValidator); +IConfig configuration = DefaultConfig.Instance + .WithOptions(ConfigOptions.DisableOptimizationsValidator) + .WithOrderer(new DefaultOrderer(SummaryOrderPolicy.FastestToSlowest)); if (args.Length > 0) {