mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-24 13:38:34 +01:00
use UiMetrics to print ui test info
This commit is contained in:
parent
2e9e6e8980
commit
db2a3dfe70
1 changed files with 12 additions and 28 deletions
|
@ -120,37 +120,25 @@ public class UiTests {
|
||||||
[Test]
|
[Test]
|
||||||
public void TestAutoAreaPerformanceDeep() {
|
public void TestAutoAreaPerformanceDeep() {
|
||||||
for (var i = 1; i <= 100; i++) {
|
for (var i = 1; i <= 100; i++) {
|
||||||
var totalUpdates = 0;
|
var main = new Group(Anchor.TopLeft, new Vector2(50));
|
||||||
var main = new Group(Anchor.TopLeft, new Vector2(50)) {
|
|
||||||
OnAreaUpdated = _ => totalUpdates++
|
|
||||||
};
|
|
||||||
var group = main;
|
var group = main;
|
||||||
for (var g = 0; g < i; g++) {
|
for (var g = 0; g < i; g++)
|
||||||
group = group.AddChild(new Group(Anchor.TopLeft, Vector2.One) {
|
group = group.AddChild(new Group(Anchor.TopLeft, Vector2.One));
|
||||||
OnAreaUpdated = _ => totalUpdates++
|
|
||||||
});
|
|
||||||
}
|
|
||||||
this.AddAndUpdate(main, out var addTime, out var updateTime);
|
this.AddAndUpdate(main, out var addTime, out var updateTime);
|
||||||
var allChildren = main.GetChildren(regardGrandchildren: true);
|
var allChildren = main.GetChildren(regardGrandchildren: true);
|
||||||
TestContext.WriteLine($"{allChildren.Count()} children, {totalUpdates} updates total, took {addTime.TotalMilliseconds * 1000000}ns to add, {updateTime.TotalMilliseconds * 1000000}ns to update");
|
TestContext.WriteLine($"{allChildren.Count()} children, took {addTime.TotalMilliseconds * 1000000}ns to add, {updateTime.TotalMilliseconds * 1000000}ns to update, metrics {this.game.UiSystem.Metrics}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestAutoAreaPerformanceSideBySide() {
|
public void TestAutoAreaPerformanceSideBySide() {
|
||||||
for (var i = 1; i <= 100; i++) {
|
for (var i = 1; i <= 100; i++) {
|
||||||
var totalUpdates = 0;
|
var main = new Group(Anchor.TopLeft, new Vector2(50));
|
||||||
var main = new Group(Anchor.TopLeft, new Vector2(50)) {
|
for (var g = 0; g < i; g++)
|
||||||
OnAreaUpdated = _ => totalUpdates++
|
main.AddChild(new Group(Anchor.AutoInlineIgnoreOverflow, new Vector2(1F / i, 1)));
|
||||||
};
|
|
||||||
for (var g = 0; g < i; g++) {
|
|
||||||
main.AddChild(new Group(Anchor.AutoInlineIgnoreOverflow, new Vector2(1F / i, 1)) {
|
|
||||||
OnAreaUpdated = _ => totalUpdates++
|
|
||||||
});
|
|
||||||
}
|
|
||||||
this.AddAndUpdate(main, out var addTime, out var updateTime);
|
this.AddAndUpdate(main, out var addTime, out var updateTime);
|
||||||
var allChildren = main.GetChildren(regardGrandchildren: true);
|
var allChildren = main.GetChildren(regardGrandchildren: true);
|
||||||
TestContext.WriteLine($"{allChildren.Count()} children, {totalUpdates} updates total, took {addTime.TotalMilliseconds * 1000000}ns to add, {updateTime.TotalMilliseconds * 1000000}ns to update");
|
TestContext.WriteLine($"{allChildren.Count()} children, took {addTime.TotalMilliseconds * 1000000}ns to add, {updateTime.TotalMilliseconds * 1000000}ns to update, metrics {this.game.UiSystem.Metrics}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,27 +146,23 @@ public class UiTests {
|
||||||
public void TestAutoAreaPerformanceRandom() {
|
public void TestAutoAreaPerformanceRandom() {
|
||||||
for (var i = 0; i <= 1000; i += 10) {
|
for (var i = 0; i <= 1000; i += 10) {
|
||||||
var random = new Random(93829345);
|
var random = new Random(93829345);
|
||||||
var totalUpdates = 0;
|
var main = new Group(Anchor.TopLeft, new Vector2(50));
|
||||||
var main = new Group(Anchor.TopLeft, new Vector2(50)) {
|
|
||||||
OnAreaUpdated = _ => totalUpdates++
|
|
||||||
};
|
|
||||||
var group = main;
|
var group = main;
|
||||||
for (var g = 0; g < i; g++) {
|
for (var g = 0; g < i; g++) {
|
||||||
var newGroup = group.AddChild(new Group(Anchor.TopLeft, Vector2.One) {
|
var newGroup = group.AddChild(new Group(Anchor.TopLeft, Vector2.One));
|
||||||
OnAreaUpdated = _ => totalUpdates++
|
|
||||||
});
|
|
||||||
if (random.NextSingle() <= 0.25F)
|
if (random.NextSingle() <= 0.25F)
|
||||||
group = newGroup;
|
group = newGroup;
|
||||||
}
|
}
|
||||||
this.AddAndUpdate(main, out var addTime, out var updateTime);
|
this.AddAndUpdate(main, out var addTime, out var updateTime);
|
||||||
var allChildren = main.GetChildren(regardGrandchildren: true);
|
var allChildren = main.GetChildren(regardGrandchildren: true);
|
||||||
TestContext.WriteLine($"{allChildren.Count()} children, {totalUpdates} updates total, took {addTime.TotalMilliseconds * 1000000}ns to add, {updateTime.TotalMilliseconds * 1000000}ns to update");
|
TestContext.WriteLine($"{allChildren.Count()} children, took {addTime.TotalMilliseconds * 1000000}ns to add, {updateTime.TotalMilliseconds * 1000000}ns to update, metrics {this.game.UiSystem.Metrics}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddAndUpdate(Element element, out TimeSpan addTime, out TimeSpan updateTime) {
|
private void AddAndUpdate(Element element, out TimeSpan addTime, out TimeSpan updateTime) {
|
||||||
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);
|
||||||
|
this.game.UiSystem.Metrics.ResetUpdates();
|
||||||
|
|
||||||
var stopwatch = Stopwatch.StartNew();
|
var stopwatch = Stopwatch.StartNew();
|
||||||
this.game.UiSystem.Add("Test", element);
|
this.game.UiSystem.Add("Test", element);
|
||||||
|
|
Loading…
Reference in a new issue