diff --git a/fennecs.benchmarks/Conceptual/CostCentersBench.cs b/fennecs.benchmarks/Conceptual/CostCentersBench.cs new file mode 100644 index 0000000..99f9c89 --- /dev/null +++ b/fennecs.benchmarks/Conceptual/CostCentersBench.cs @@ -0,0 +1,54 @@ +using BenchmarkDotNet.Attributes; +using fennecs; + +namespace Benchmark.Conceptual; + +public class CostCentersBench +{ + [Params(10000)] + public int Count { get; set; } + + private World _world = null!; + private Stream _streamOne = null!; + private Stream _streamMany = null!; + + [GlobalSetup] + public void Setup() + { + _world = new(Count * 3); + + for (var i = 0; i < Count; i++) + { + _world.Spawn().Add(i); + } + + for (var i = 0; i < Count; i++) + { + var unique = _world.Spawn(); + _world.Spawn().Add(i).Add("relation", unique); + } + + _streamOne = _world.Query().Not(Match.Any).Stream(); + _streamMany = _world.Query().Has(Match.Any).Stream(); + + Console.WriteLine($"World: {_world.Count} Entities"); + Console.WriteLine($"Stream One: {_streamOne.Count} Entities, {_streamOne.Query.Archetypes.Count} Archetypes"); + Console.WriteLine($"Stream Many: {_streamMany.Count} Entities, {_streamMany.Query.Archetypes.Count} Archetypes"); + } + + [Benchmark] + public int SingleArchetype() + { + var output = 0; + _streamOne.For((ref int value) => { output += value; }); + return output; + } + + [Benchmark] + public int ManyArchetypes() + { + var output = 0; + _streamMany.For((ref int value) => { output += value; }); + return output; + } +} diff --git a/fennecs.benchmarks/Conceptual/EventsVsListsBench.cs b/fennecs.benchmarks/Conceptual/EventsVsListsBench.cs new file mode 100644 index 0000000..201916f --- /dev/null +++ b/fennecs.benchmarks/Conceptual/EventsVsListsBench.cs @@ -0,0 +1,96 @@ +using BenchmarkDotNet.Attributes; + +namespace Benchmark.Conceptual; + +public class EventsVsListsBench +{ + [Params(100)] + public int Count { get; set; } + + private List> _listeners = null!; + private event Action? Event = null!; + + [GlobalSetup] + public void Setup() + { + _listeners = new(1_000_000) + { + OnEvent, + }; + Event += OnEvent; + } + + private int _sum; + private Random _rnd = null!; + private void OnEvent(int number) + { + _sum += number; + } + + [IterationSetup] + public void SetupEvents() + { + _sum = 0; + _rnd = new(); + + _listeners.Clear(); + Event = null!; + + for (var i = 0; i < Count; i++) + { + _listeners.Add(OnEvent); + Event += OnEvent; + } + } + + + [Benchmark] + public void AddListeners() + { + for (var i = 0; i < 10_000; i++) + { + _listeners.Add(OnEvent); + } + + for (var i = 0; i < 10_000; i++) + { + _listeners.Remove(OnEvent); + } + } + + [Benchmark] + public void AddEvents() + { + for (var i = 0; i < 10_000; i++) + { + Event += OnEvent; + } + + for (var i = 0; i < 10_000; i++) + { + Event -= OnEvent; + } + } + + [Benchmark(Baseline = true)] + public int InvokeEvents() + { + for (var i = 0; i < 1_000_000; i++) + { + var number = _rnd.Next(); + Event?.Invoke(number); + } + return _sum; + } + + [Benchmark] + public int InvokeListeners() + { + for (var i = 0; i < 1_000_000; i++) + { + var number = _rnd.Next(); + foreach (var action in _listeners) action(number); + } + return _sum; + } +} diff --git a/fennecs.benchmarks/Program.cs b/fennecs.benchmarks/Program.cs index 3120b86..93d7664 100644 --- a/fennecs.benchmarks/Program.cs +++ b/fennecs.benchmarks/Program.cs @@ -11,8 +11,18 @@ var config = ManualConfig .Create(DefaultConfig.Instance) .WithOptions(ConfigOptions.JoinSummary) - .AddJob(Job.ShortRun.WithRuntime(CoreRuntime.Core90)) - .AddJob(Job.ShortRun.WithRuntime(NativeAotRuntime.Net90)) + + .AddJob( + Job.ShortRun.WithId("Default") + .WithRuntime(CoreRuntime.Core90) + ) + + /* + .AddJob( + Job.ShortRun.WithId("Native") + .WithRuntime(NativeAotRuntime.Net90) + ) + */ .HideColumns("Job", "Error", "Median", "RatioSD"); // Most relevant vectorization instruction sets, add other intrinsics as needed. @@ -25,5 +35,4 @@ if (!AdvSimd.IsSupported) config.AddFilter(new CategoryExclusion(nameof(AdvSimd))); -//BenchmarkRunner.Run(config); -BenchmarkRunner.Run(config); +BenchmarkRunner.Run(config); diff --git a/fennecs.benchmarks/fennecs.benchmarks.csproj b/fennecs.benchmarks/fennecs.benchmarks.csproj index 67e3b49..ff8fd6e 100644 --- a/fennecs.benchmarks/fennecs.benchmarks.csproj +++ b/fennecs.benchmarks/fennecs.benchmarks.csproj @@ -12,24 +12,24 @@ fennecs.benchmarks true false - preview + 13 true Speed - - x64 - - - x64 + x64 + true + true + true + true - + - + diff --git a/fennecs/fennecs.csproj b/fennecs/fennecs.csproj index 55ccd14..ef8d4fb 100644 --- a/fennecs/fennecs.csproj +++ b/fennecs/fennecs.csproj @@ -5,10 +5,10 @@ enable enable fennecs - 0.5.14-beta + 0.6.0-beta fennecs fennecs Entity-Component System - Moritz Voss, Aaron Winter + Moritz Voss and Contributors tiger.blue The tiny ECS that could! 2024 Moritz Voss, 2022 Aaron Winter @@ -34,6 +34,11 @@ true true true + + true + true + false + false