From 177addcaf6865bc88d978a2eb0f3b706107705e2 Mon Sep 17 00:00:00 2001 From: Tiger Jove Date: Tue, 12 Nov 2024 00:15:55 +0100 Subject: [PATCH] Ended up writing a lot of theoretical tests... --- .../Conceptual/CostCentersBench.cs | 4 ++-- fennecs.benchmarks/ECS/DorakuBenchmarks.cs | 14 ++--------- fennecs.benchmarks/Program.cs | 24 ++++++++----------- fennecs.tests/ArchetypeTests.cs | 1 + fennecs.tests/Conceptual/ReflectionTests.cs | 22 +++++++++++++++++ fennecs.tests/StorageTests.cs | 4 +++- fennecs/Archetype.cs | 1 + fennecs/Cross.cs | 1 + fennecs/{ => storage}/Storage.cs | 2 +- 9 files changed, 43 insertions(+), 30 deletions(-) create mode 100644 fennecs.tests/Conceptual/ReflectionTests.cs rename fennecs/{ => storage}/Storage.cs (99%) diff --git a/fennecs.benchmarks/Conceptual/CostCentersBench.cs b/fennecs.benchmarks/Conceptual/CostCentersBench.cs index 99f9c89e..69c5b1a8 100644 --- a/fennecs.benchmarks/Conceptual/CostCentersBench.cs +++ b/fennecs.benchmarks/Conceptual/CostCentersBench.cs @@ -37,7 +37,7 @@ public void Setup() } [Benchmark] - public int SingleArchetype() + public int FewArchetypesManyEntities() { var output = 0; _streamOne.For((ref int value) => { output += value; }); @@ -45,7 +45,7 @@ public int SingleArchetype() } [Benchmark] - public int ManyArchetypes() + public int ManyArchetypesFewEntities() { var output = 0; _streamMany.For((ref int value) => { output += value; }); diff --git a/fennecs.benchmarks/ECS/DorakuBenchmarks.cs b/fennecs.benchmarks/ECS/DorakuBenchmarks.cs index 29f18abc..f4509ce2 100644 --- a/fennecs.benchmarks/ECS/DorakuBenchmarks.cs +++ b/fennecs.benchmarks/ECS/DorakuBenchmarks.cs @@ -12,7 +12,6 @@ namespace Benchmark.ECS; -[ShortRunJob] //[TailCallDiagnoser] [ThreadingDiagnoser] [MemoryDiagnoser] @@ -91,7 +90,7 @@ public void fennecs_For() [BenchmarkCategory("fennecs")] - //[Benchmark(Description = "fennecs (For WL)")] + [Benchmark(Description = "fennecs (For WL)")] public void fennecs_For_WL() { _query.For(Workload); @@ -99,7 +98,7 @@ public void fennecs_For_WL() [BenchmarkCategory("fennecs")] - //[Benchmark(Description = $"fennecs (Job)")] + [Benchmark(Description = $"fennecs (Job)")] public void fennecs_Job() { _query.Job(static delegate (ref Component1 c1, ref Component2 c2, ref Component3 c3) { c1.Value = c1.Value + c2.Value + c3.Value; }); @@ -318,15 +317,6 @@ private static void Raw_Workload_Tensor(Memory c1V, Memory(c2V.Span); var c3I = MemoryMarshal.Cast(c3V.Span); - /* - var c1I = c1V.Span; - var c2I = c2V.Span; - var c3I = c3V.Span; - */ - - //stackalloc float array - //Span intermediate = stackalloc float[c1V.Length]; - TensorPrimitives.Add(c2I, c1I, c1I); TensorPrimitives.Add(c3I, c1I, c1I); } diff --git a/fennecs.benchmarks/Program.cs b/fennecs.benchmarks/Program.cs index 93d76648..32121d21 100644 --- a/fennecs.benchmarks/Program.cs +++ b/fennecs.benchmarks/Program.cs @@ -1,7 +1,7 @@ using System.Runtime.Intrinsics.Arm; using System.Runtime.Intrinsics.X86; using Benchmark; -using Benchmark.Conceptual; +using Benchmark.ECS; using BenchmarkDotNet.Configs; using BenchmarkDotNet.Environments; using BenchmarkDotNet.Jobs; @@ -11,20 +11,16 @@ var config = ManualConfig .Create(DefaultConfig.Instance) .WithOptions(ConfigOptions.JoinSummary) - - .AddJob( - Job.ShortRun.WithId("Default") - .WithRuntime(CoreRuntime.Core90) - ) - - /* - .AddJob( - Job.ShortRun.WithId("Native") - .WithRuntime(NativeAotRuntime.Net90) - ) - */ .HideColumns("Job", "Error", "Median", "RatioSD"); +var jobs = new List([ + Job.ShortRun.WithId("Default").WithRuntime(CoreRuntime.Core90), + Job.ShortRun.WithId("Native").WithRuntime(NativeAotRuntime.Net90), +]); + + +foreach (var job in jobs) config.AddJob(job); + // Most relevant vectorization instruction sets, add other intrinsics as needed. // These are exclusions you can use to TURN OFF specific benchmarks based on the // supported feature of the system. @@ -35,4 +31,4 @@ if (!AdvSimd.IsSupported) config.AddFilter(new CategoryExclusion(nameof(AdvSimd))); -BenchmarkRunner.Run(config); +BenchmarkRunner.Run(config); diff --git a/fennecs.tests/ArchetypeTests.cs b/fennecs.tests/ArchetypeTests.cs index 58fccfea..ca209427 100644 --- a/fennecs.tests/ArchetypeTests.cs +++ b/fennecs.tests/ArchetypeTests.cs @@ -1,4 +1,5 @@ using System.Collections; +using fennecs.storage; namespace fennecs.tests; diff --git a/fennecs.tests/Conceptual/ReflectionTests.cs b/fennecs.tests/Conceptual/ReflectionTests.cs new file mode 100644 index 00000000..7b9782e5 --- /dev/null +++ b/fennecs.tests/Conceptual/ReflectionTests.cs @@ -0,0 +1,22 @@ +namespace fennecs.tests.Conceptual; + +using fennecs.storage; + +public class ReflectionTests +{ + [Fact] + public void MakeGenericType_is_Not_Unique() + { + var t1 = typeof(Storage<>).MakeGenericType(typeof(int)); + var t2 = typeof(Storage<>).MakeGenericType(typeof(int)); + Assert.Equal(t1, t2); + } + + [Fact] + public void MakeGenericType_is_Same_As_Static() + { + var t1 = typeof(Storage<>).MakeGenericType(typeof(int)); + var t2 = typeof(Storage); + Assert.Equal(t1, t2); + } +} diff --git a/fennecs.tests/StorageTests.cs b/fennecs.tests/StorageTests.cs index e1c56977..bea54b89 100644 --- a/fennecs.tests/StorageTests.cs +++ b/fennecs.tests/StorageTests.cs @@ -1,4 +1,6 @@ -namespace fennecs.tests; +using fennecs.storage; + +namespace fennecs.tests; public class StorageTests { diff --git a/fennecs/Archetype.cs b/fennecs/Archetype.cs index d1822a38..d12c090d 100644 --- a/fennecs/Archetype.cs +++ b/fennecs/Archetype.cs @@ -4,6 +4,7 @@ using System.Text; using System.Runtime.CompilerServices; using fennecs.pools; +using fennecs.storage; // ReSharper disable ForeachCanBeConvertedToQueryUsingAnotherGetEnumerator diff --git a/fennecs/Cross.cs b/fennecs/Cross.cs index 76ffc532..86507ca3 100644 --- a/fennecs/Cross.cs +++ b/fennecs/Cross.cs @@ -1,6 +1,7 @@ using System.Buffers; using System.Diagnostics; using fennecs.pools; +using fennecs.storage; namespace fennecs; diff --git a/fennecs/Storage.cs b/fennecs/storage/Storage.cs similarity index 99% rename from fennecs/Storage.cs rename to fennecs/storage/Storage.cs index 9fbc66a5..9a463f7a 100644 --- a/fennecs/Storage.cs +++ b/fennecs/storage/Storage.cs @@ -3,7 +3,7 @@ using System.Runtime.CompilerServices; using fennecs.pools; -namespace fennecs; +namespace fennecs.storage; /// /// Generic Storage Interface (with boxing).