Skip to content

Commit

Permalink
Engine - Tests: add Test_Entity_Tree_Allocation()
Browse files Browse the repository at this point in the history
  • Loading branch information
friflo committed Jul 19, 2024
1 parent 17596ba commit 4c4e5f4
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion Engine/src/Tests/ECS/Entity/Test_Entity_Tree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Friflo.Engine.ECS;
using NUnit.Framework;
using Tests.Utils;
Expand Down Expand Up @@ -425,8 +426,48 @@ public static void Test_Entity_Tree_move_with_AddChild()
}

[Test]
public static void Test_Entity_Tree_Allocation() {
public static void Test_Entity_Tree_Allocation()
{
int count = 10; // 1000
// Test_Entity_Tree_Allocation - count: 1000 entities: 1001001 duration: 360 ms
var store = new EntityStore();
var root = store.CreateEntity(1);
var type = store.GetArchetype(default);
var children = type.CreateEntities(count).ToArray();
var subChildren = type.CreateEntities(count * count).ToArray();
store.SetStoreRoot(root);

for (int repeat = 0; repeat < 2; repeat++)
{
var sw = new Stopwatch();
sw.Start();
var start = Mem.GetAllocatedBytes();
int subIndex = 0;
foreach (var child in children)
{
root.AddChild(child);
for (int i = 0; i < count; i++) {
var subChild = subChildren[subIndex++];
child.AddChild(subChild);
}
Mem.AreEqual(count, child.ChildCount);
}
Mem.AreEqual(count, root.ChildCount);

for (int n = count - 1; n >= 0; n--)
{
var child = children[n];
var childEntities = child.ChildEntities;
for (int i = count - 1; i >= 0; i--) {
Mem.IsTrue(child.RemoveChild(childEntities[i]));
}
Mem.IsTrue(root.RemoveChild(child));
}
if (repeat > 0) {
Mem.AssertNoAlloc(start);
Console.WriteLine($"Test_Entity_Tree_Allocation - count: {count} entities: {store.Count} duration: {sw.ElapsedMilliseconds} ms");
}
}
}

[Test]
Expand Down

0 comments on commit 4c4e5f4

Please sign in to comment.