-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActorCheckComponentExistsBenchmark.cs
More file actions
195 lines (166 loc) · 6.52 KB
/
Copy pathActorCheckComponentExistsBenchmark.cs
File metadata and controls
195 lines (166 loc) · 6.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
using Friflo.Engine.ECS;
using Hexecs.Benchmarks.Mocks.ActorComponents;
using Hexecs.Worlds;
using World = Hexecs.Worlds.World;
namespace Hexecs.Benchmarks.Actors;
// BenchmarkDotNet v0.15.8, Windows 11 (10.0.22621.4317/22H2/2022Update/SunValley2)
// Intel Xeon CPU E5-2697 v3 2.60GHz, 2 CPU, 56 logical and 28 physical cores
// .NET SDK 10.0.102
// [Host] : .NET 10.0.2 (10.0.2, 10.0.225.61305), X64 RyuJIT x86-64-v3
// .NET 10.0 : .NET 10.0.2 (10.0.2, 10.0.225.61305), X64 RyuJIT x86-64-v3
//
// Job=.NET 10.0 Runtime=.NET 10.0
//
// | Method | Count | Mean | Ratio | Allocated | Alloc Ratio |
// |----------------- |------- |----------:|------:|----------:|------------:|
// | Hexecs_Is | 10000 | 14.55 us | 0.88 | - | NA |
// | Hexecs_Reference | 10000 | 15.92 us | 0.96 | - | NA |
// | Hexecs_Has | 10000 | 16.58 us | 1.00 | - | NA |
// | FriFlo_Has | 10000 | 40.36 us | 2.43 | - | NA |
// | DefaultEcs_Has | 10000 | 72.01 us | 4.34 | - | NA |
// | | | | | | |
// | Hexecs_Is | 100000 | 149.57 us | 0.93 | - | NA |
// | Hexecs_Has | 100000 | 161.46 us | 1.00 | - | NA |
// | Hexecs_Reference | 100000 | 163.02 us | 1.01 | - | NA |
// | FriFlo_Has | 100000 | 409.32 us | 2.54 | - | NA |
// | DefaultEcs_Has | 100000 | 730.64 us | 4.53 | - | NA |
//
// ------------------------------------------------------------------------------------
//
// BenchmarkDotNet v0.15.8, macOS Tahoe 26.2 (25C56) [Darwin 25.2.0]
// Apple M3 Max, 1 CPU, 16 logical and 16 physical cores
// .NET SDK 10.0.102
// [Host] : .NET 10.0.1 (10.0.1, 10.0.125.57005), Arm64 RyuJIT armv8.0-a
// .NET 10.0 : .NET 10.0.2 (10.0.2, 10.0.225.61305), Arm64 RyuJIT armv8.0-a
//
// Job=.NET 10.0 Runtime=.NET 10.0
//
// | Method | Count | Mean | Ratio | Allocated | Alloc Ratio |
// |----------------- |------- |-----------:|------:|----------:|------------:|
// | Hexecs_Is | 10000 | 9.916 us | 0.90 | - | NA |
// | Hexecs_Has | 10000 | 10.960 us | 1.00 | - | NA |
// | Hexecs_Reference | 10000 | 11.301 us | 1.03 | - | NA |
// | FriFlo_Has | 10000 | 16.540 us | 1.51 | - | NA |
// | DefaultEcs_Has | 10000 | 25.877 us | 2.36 | - | NA |
// | | | | | | |
// | Hexecs_Is | 100000 | 98.966 us | 0.90 | - | NA |
// | Hexecs_Has | 100000 | 110.039 us | 1.00 | - | NA |
// | Hexecs_Reference | 100000 | 112.981 us | 1.03 | - | NA |
// | FriFlo_Has | 100000 | 159.346 us | 1.45 | - | NA |
// | DefaultEcs_Has | 100000 | 256.135 us | 2.33 | - | NA |
[SimpleJob(RuntimeMoniker.Net10_0)]
[Orderer(SummaryOrderPolicy.FastestToSlowest)]
[MeanColumn, MemoryDiagnoser]
[HideColumns("Job", "Error", "StdDev", "Median", "RatioSD")]
[JsonExporterAttribute.Full]
[JsonExporterAttribute.FullCompressed]
[BenchmarkCategory("Actors")]
public class ActorCheckComponentExistsBenchmark
{
[Params(10_000, 100_000)] public int Count;
private ActorContext _context = null!;
private DefaultEcs.World _defaultWorld = null!;
private EntityStore _frifloWorld = null!;
private ArchetypeQuery _frifloAllEntitiesQuery = null!;
private World _world = null!;
[Benchmark(Baseline = true)]
public int Hexecs_Has()
{
var result = 0;
// ReSharper disable once ForeachCanBeConvertedToQueryUsingAnotherGetEnumerator
foreach (var actor in _context)
{
if (actor.Has<Speed>()) result++;
}
return result;
}
[Benchmark]
public int DefaultEcs_Has()
{
var result = 0;
// ReSharper disable once ForeachCanBeConvertedToQueryUsingAnotherGetEnumerator
foreach (var entity in _defaultWorld)
{
if (entity.Has<Speed>())
{
result++;
}
}
return result;
}
[Benchmark]
public int FriFlo_Has()
{
var result = 0;
// ReSharper disable once ForeachCanBeConvertedToQueryUsingAnotherGetEnumerator
foreach (var entity in _frifloAllEntitiesQuery.Entities)
{
if (entity.HasComponent<Speed>())
{
result++;
}
}
return result;
}
[Benchmark]
public int Hexecs_Is()
{
var result = 0;
// ReSharper disable once ForeachCanBeConvertedToQueryUsingAnotherGetEnumerator
foreach (var actor in _context)
{
if (actor.Is<Speed>(out _))
{
result++;
}
}
return result;
}
[Benchmark]
public int Hexecs_Reference()
{
var result = 0;
// ReSharper disable once ForeachCanBeConvertedToQueryUsingAnotherGetEnumerator
foreach (var actor in _context)
{
ref var reference = ref actor.TryGetRef<Speed>();
if (!Unsafe.IsNullRef(ref reference))
{
result++;
}
}
return result;
}
[GlobalCleanup]
public void Cleanup()
{
_defaultWorld.Dispose();
_defaultWorld = null!;
_frifloWorld = null!;
_world.Dispose();
_world = null!;
}
[GlobalSetup]
public void Setup()
{
_defaultWorld = new DefaultEcs.World();
_frifloWorld = new EntityStore();
_frifloAllEntitiesQuery = _frifloWorld.Query();
_world = new WorldBuilder().Build();
_context = _world.Actors;
for (var i = 0; i < Count; i++)
{
var actor = _context.CreateActor();
actor.Add(new Attack());
actor.Add(new Defence());
var defaultEntity = _defaultWorld.CreateEntity();
defaultEntity.Set<Attack>();
defaultEntity.Set<Defence>();
var frifloEntity = _frifloWorld.CreateEntity(new Attack(), new Defence());
if (i % 10 != 0) continue;
actor.Add(new Speed());
defaultEntity.Set<Speed>();
frifloEntity.Add(new Speed());
}
}
}