A game framework written with osu! in mind.
at master 162 lines 4.1 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 BenchmarkBeginAbsoluteSequence : GameBenchmark 16 { 17 private TestGame game; 18 19 [Test] 20 [Benchmark] 21 public void NonRecursive() 22 { 23 game.Schedule(() => 24 { 25 using (game.Flat.BeginAbsoluteSequence(1000, false)) 26 { 27 } 28 }); 29 30 RunSingleFrame(); 31 } 32 33 [Test] 34 [Benchmark] 35 public void Recursive() 36 { 37 game.Schedule(() => 38 { 39 using (game.Flat.BeginAbsoluteSequence(1000, true)) 40 { 41 } 42 }); 43 44 RunSingleFrame(); 45 } 46 47 [Test] 48 [Benchmark] 49 public void SlightlyNestedNonRecursive() 50 { 51 game.Schedule(() => 52 { 53 using (game.SlightlyNested.BeginAbsoluteSequence(1000, false)) 54 { 55 } 56 }); 57 58 RunSingleFrame(); 59 } 60 61 [Test] 62 [Benchmark] 63 public void SlightlyNestedRecursive() 64 { 65 game.Schedule(() => 66 { 67 using (game.SlightlyNested.BeginAbsoluteSequence(1000, true)) 68 { 69 } 70 }); 71 72 RunSingleFrame(); 73 } 74 75 [Test] 76 [Benchmark] 77 public void VeryNestedNonRecursive() 78 { 79 game.Schedule(() => 80 { 81 using (game.VeryNested.BeginAbsoluteSequence(1000, false)) 82 { 83 } 84 }); 85 86 RunSingleFrame(); 87 } 88 89 [Test] 90 [Benchmark] 91 public void VeryNestedRecursive() 92 { 93 game.Schedule(() => 94 { 95 using (game.VeryNested.BeginAbsoluteSequence(1000, true)) 96 { 97 } 98 }); 99 100 RunSingleFrame(); 101 } 102 103 protected override Game CreateGame() => game = new TestGame(); 104 105 private class TestGame : Game 106 { 107 public Container Flat; 108 public Container VeryNested; 109 public Container SlightlyNested; 110 111 protected override void LoadComplete() 112 { 113 base.LoadComplete(); 114 115 Add(Flat = new Container()); 116 117 for (int i = 0; i < 1000; i++) 118 { 119 var box = new Box 120 { 121 Size = new Vector2(100), 122 Colour = Color4.Black 123 }; 124 125 Flat.Add(box); 126 } 127 128 Add(SlightlyNested = new Container()); 129 130 for (int i = 0; i < 1000; i++) 131 { 132 SlightlyNested.Add(new Container 133 { 134 Size = new Vector2(100), 135 Colour = Color4.Black, 136 Children = new Drawable[] 137 { 138 new Box 139 { 140 Colour = Color4.Black, 141 RelativeSizeAxes = Axes.Both, 142 }, 143 } 144 }); 145 } 146 147 Add(VeryNested = new Container()); 148 149 Container target = VeryNested; 150 151 for (int i = 0; i < 1000; i++) 152 { 153 var container = new Container { Size = new Vector2(100), Colour = Color4.Black }; 154 155 target.Add(container); 156 157 target = container; 158 } 159 } 160 } 161 } 162}