Skip to content

Commit ce09763

Browse files
committed
Add benchmark
1 parent a4c5157 commit ce09763

File tree

2 files changed

+71
-33
lines changed

2 files changed

+71
-33
lines changed

src/Arch.Benchmarks/Benchmark.cs

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,16 @@
11
using System.Numerics;
22
using Arch.Core;
33
using Arch.Core.Extensions;
4+
45
using Arch.Core.Utils;
56

67
namespace Arch.Benchmarks;
78

89
public class Benchmark
910
{
10-
private static void Main(string[] args)
11+
public static void Main(string[] args)
1112
{
12-
/*
13-
// NOTE: Can this be replaced with ManualConfig.CreateEmpty()?
14-
#pragma warning disable HAA0101 // Array allocation for params parameter
15-
var config = new ManualConfig()
16-
.WithOptions(ConfigOptions.DisableOptimizationsValidator)
17-
.AddValidator(JitOptimizationsValidator.DontFailOnError)
18-
.AddLogger(ConsoleLogger.Default)
19-
.AddColumnProvider(DefaultColumnProviders.Instance);
20-
#pragma warning restore HAA0101 // Array allocation for params parameter
21-
*/
22-
23-
24-
25-
var world = World.Create();
26-
for (var index = 0; index <= 100; index++)
27-
{
28-
world.Create<int>();
29-
}
30-
31-
var desc = new QueryDescription().WithAll<int>();
32-
for (var index = 0; index <= 100000; index++)
33-
{
34-
world.Query(in desc, (ref int i) =>
35-
{
36-
});
37-
}
38-
39-
40-
41-
// NOTE: Is `-- --job` a typo?
42-
// Use: dotnet run -c Release --framework net7.0 -- --job short --filter *IterationBenchmark*
43-
//BenchmarkSwitcher.FromAssembly(typeof(Benchmark).Assembly).Run(args, config);
13+
BenchmarkSwitcher.FromAssembly(typeof(Benchmark).Assembly).Run(args);
14+
//BenchmarkSwitcher.FromAssembly(typeof(Benchmark).Assembly).Run(args, new DebugInProcessConfig());
4415
}
4516
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using Arch.Core;
2+
using Arch.Core.Utils;
3+
4+
namespace Arch.Benchmarks;
5+
6+
[HtmlExporter]
7+
//[MemoryDiagnoser]
8+
//[HardwareCounters(HardwareCounter.CacheMisses)]
9+
public class DuplicateBenchmark
10+
{
11+
public int Amount = 100000;
12+
13+
private static readonly ComponentType[] _group = { typeof(Transform), typeof(Velocity) };
14+
private readonly QueryDescription _queryDescription = new(all: _group);
15+
16+
private static World? _world;
17+
private static Entity _entity = Entity.Null;
18+
private static Entity[]? _array = null;
19+
20+
[IterationSetup]
21+
public void Setup()
22+
{
23+
_world = World.Create();
24+
_world.Reserve(_group, 1);
25+
_entity = _world.Create(new Transform { X = 111, Y = 222}, new Velocity { X = 333, Y = 444 });
26+
_array = new Entity[Amount];
27+
}
28+
29+
[IterationCleanup]
30+
public void Cleanup()
31+
{
32+
World.Destroy(_world);
33+
_world = null;
34+
}
35+
36+
/// DuplicateN() method.
37+
[Benchmark]
38+
public void DuplicateNInternal()
39+
{
40+
_world.DuplicateN(_entity, _array.AsSpan());
41+
}
42+
43+
/// DuplicateN() in terms of Duplicate() method.
44+
[Benchmark]
45+
public void DuplicateNDuplicate()
46+
{
47+
for (int i = 0; i < Amount; ++i)
48+
{
49+
_array[i] = _world.Duplicate(_entity);
50+
}
51+
}
52+
53+
/// Benchmark DuplicateN() if implemented via GetAllComponents.
54+
[Benchmark]
55+
public void DuplicateNGetAllComponents()
56+
{
57+
for (int i = 0; i < Amount; ++i)
58+
{
59+
var arch = _world.GetArchetype(_entity);
60+
var copiedEntity = _world.Create(arch.Signature);
61+
foreach (var c in _world.GetAllComponents(_entity))
62+
{
63+
_world.Set(_entity, c);
64+
}
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)