mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Add benchmark for archetype indexing by handle vs array access vs field direct access (#3801)
This commit is contained in:
@@ -482,7 +482,7 @@ public class ArchetypeComponentAccessBenchmark
|
||||
public struct Struct9{}
|
||||
public struct Struct10{}
|
||||
|
||||
private sealed class Archetype<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>
|
||||
public sealed class Archetype<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>
|
||||
{
|
||||
private int _nextId;
|
||||
private readonly Dictionary<int, int> _ids;
|
||||
|
||||
53
Robust.Benchmarks/EntityManager/ComponentPassingBenchmark.cs
Normal file
53
Robust.Benchmarks/EntityManager/ComponentPassingBenchmark.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using Robust.Shared.Analyzers;
|
||||
using static Robust.Benchmarks.EntityManager.ArchetypeComponentAccessBenchmark;
|
||||
|
||||
namespace Robust.Benchmarks.EntityManager;
|
||||
|
||||
[MemoryDiagnoser]
|
||||
[Virtual]
|
||||
public class ArrayAccessBenchmark
|
||||
{
|
||||
[Params(new[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9})]
|
||||
public int[] Array = default!;
|
||||
|
||||
[Params(5)]
|
||||
public int Element;
|
||||
|
||||
[Params(500)]
|
||||
public int Handle;
|
||||
|
||||
public Archetype<int, int, int, int, int, int, int, int, int, int> Archetype = default!;
|
||||
|
||||
[GlobalSetup]
|
||||
public void GlobalSetup()
|
||||
{
|
||||
Archetype = new Archetype<int, int, int, int, int, int, int, int, int, int>(1000);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public int? GetArrayElement()
|
||||
{
|
||||
return Consume();
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public int? GetExisting()
|
||||
{
|
||||
return Consume(Element);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public int? GetArchetype()
|
||||
{
|
||||
return Consume(Archetype.GetComponentUnsafeHandle<int>(Handle));
|
||||
}
|
||||
|
||||
private int? Consume(int? value = null)
|
||||
{
|
||||
if (value == null)
|
||||
value = Array[5];
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user