A game framework written with osu! in mind.
at master 2.8 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using BenchmarkDotNet.Attributes; 5using NUnit.Framework; 6using osu.Framework.Graphics; 7using osu.Framework.Graphics.Containers; 8using osu.Framework.Graphics.Shapes; 9using osuTK; 10using osuTK.Graphics; 11 12namespace osu.Framework.Benchmarks 13{ 14 [MemoryDiagnoser] 15 public class BenchmarkDrawableLoad : GameBenchmark 16 { 17 private TestGame game; 18 19 [Test] 20 [Benchmark] 21 public void NonRecursive() 22 { 23 game.Schedule(() => 24 { 25 Container container = new Container(); 26 27 for (int i = 0; i < 1000; i++) 28 { 29 var box = new Box 30 { 31 Size = new Vector2(100), 32 Colour = Color4.Black 33 }; 34 35 container.Add(box); 36 } 37 38 game.Clear(); 39 game.Add(container); 40 }); 41 42 RunSingleFrame(); 43 } 44 45 [Test] 46 [Benchmark] 47 public void SlightlyNested() 48 { 49 game.Schedule(() => 50 { 51 Container container = new Container(); 52 53 for (int i = 0; i < 1000; i++) 54 { 55 container.Add(new Container 56 { 57 Size = new Vector2(100), 58 Colour = Color4.Black, 59 Children = new Drawable[] 60 { 61 new Box 62 { 63 Colour = Color4.Black, 64 RelativeSizeAxes = Axes.Both, 65 }, 66 } 67 }); 68 } 69 70 game.Clear(); 71 game.Add(container); 72 }); 73 74 RunSingleFrame(); 75 } 76 77 [Test] 78 [Benchmark] 79 public void VeryNested() 80 { 81 game.Schedule(() => 82 { 83 Container container = new Container(); 84 Container target = container; 85 86 for (int i = 0; i < 1000; i++) 87 { 88 var newContainer = new Container { Size = new Vector2(100), Colour = Color4.Black }; 89 90 target.Add(newContainer); 91 target = newContainer; 92 } 93 94 game.Clear(); 95 game.Add(container); 96 }); 97 98 RunSingleFrame(); 99 } 100 101 protected override Game CreateGame() => game = new TestGame(); 102 103 private class TestGame : Game 104 { 105 } 106 } 107}