forked from DeltaV-Station/Delta-v
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathDynamicTreeBenchmark.cs
68 lines (61 loc) · 2.24 KB
/
DynamicTreeBenchmark.cs
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
using BenchmarkDotNet.Attributes;
using Robust.Shared.Analyzers;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
namespace Content.Benchmarks
{
[SimpleJob, MemoryDiagnoser]
[Virtual]
public class DynamicTreeBenchmark
{
private static readonly Box2[] Aabbs1 =
{
((Box2) default).Enlarged(1), //2x2 square
((Box2) default).Enlarged(2), //4x4 square
new(-3, 3, -3, 3), // point off to the bottom left
new(-3, -3, -3, -3), // point off to the top left
new(3, 3, 3, 3), // point off to the bottom right
new(3, -3, 3, -3), // point off to the top right
((Box2) default).Enlarged(1), //2x2 square
((Box2) default).Enlarged(2), //4x4 square
((Box2) default).Enlarged(1), //2x2 square
((Box2) default).Enlarged(2), //4x4 square
((Box2) default).Enlarged(1), //2x2 square
((Box2) default).Enlarged(2), //4x4 square
((Box2) default).Enlarged(1), //2x2 square
((Box2) default).Enlarged(2), //4x4 square
((Box2) default).Enlarged(3), //6x6 square
new(-3, 3, -3, 3), // point off to the bottom left
new(-3, -3, -3, -3), // point off to the top left
new(3, 3, 3, 3), // point off to the bottom right
new(3, -3, 3, -3), // point off to the top right
};
private B2DynamicTree<int> _b2Tree;
private DynamicTree<int> _tree;
[GlobalSetup]
public void Setup()
{
_b2Tree = new B2DynamicTree<int>();
_tree = new DynamicTree<int>((in int value) => Aabbs1[value], capacity: 16);
for (var i = 0; i < Aabbs1.Length; i++)
{
var aabb = Aabbs1[i];
_b2Tree.CreateProxy(aabb, i);
_tree.Add(i);
}
}
[Benchmark]
public void BenchB2()
{
object state = null;
_b2Tree.Query(ref state, (ref object _, DynamicTree.Proxy __) => true, new Box2(-1, -1, 1, 1));
}
[Benchmark]
public void BenchQ()
{
foreach (var _ in _tree.QueryAabb(new Box2(-1, -1, 1, 1), true))
{
}
}
}
}