mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 12:58:33 +01:00
added a test for element auto-area performance
This commit is contained in:
parent
ef83124cfa
commit
d1ce9412a2
1 changed files with 23 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using MLEM.Misc;
|
using MLEM.Misc;
|
||||||
|
@ -83,6 +84,28 @@ namespace Tests {
|
||||||
Assert.AreEqual("custom", style.Value);
|
Assert.AreEqual("custom", style.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestAutoAreaPerformance() {
|
||||||
|
var stopwatch = new Stopwatch();
|
||||||
|
for (var i = 1; i <= 100; i++) {
|
||||||
|
var totalUpdates = 0;
|
||||||
|
var main = new Group(Anchor.TopLeft, new Vector2(50)) {
|
||||||
|
OnAreaUpdated = e => totalUpdates++
|
||||||
|
};
|
||||||
|
var group = main;
|
||||||
|
for (var g = 0; g < i; g++) {
|
||||||
|
group = group.AddChild(new Group(Anchor.TopLeft, Vector2.One) {
|
||||||
|
OnAreaUpdated = e => totalUpdates++
|
||||||
|
});
|
||||||
|
}
|
||||||
|
stopwatch.Restart();
|
||||||
|
this.AddAndUpdate(main);
|
||||||
|
stopwatch.Stop();
|
||||||
|
var allChildren = main.GetChildren(regardGrandchildren: true);
|
||||||
|
TestContext.WriteLine($"{allChildren.Count()} children, {totalUpdates} updates total, took {stopwatch.Elapsed.TotalMilliseconds * 1000000}ns");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void AddAndUpdate(Element element) {
|
private void AddAndUpdate(Element element) {
|
||||||
foreach (var root in this.game.UiSystem.GetRootElements())
|
foreach (var root in this.game.UiSystem.GetRootElements())
|
||||||
this.game.UiSystem.Remove(root.Name);
|
this.game.UiSystem.Remove(root.Name);
|
||||||
|
|
Loading…
Reference in a new issue