A game framework written with osu! in mind.
at master 4.3 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 System; 5using BenchmarkDotNet.Attributes; 6using osu.Framework.Graphics; 7using osu.Framework.Graphics.Shapes; 8using osu.Framework.Graphics.Transforms; 9using osu.Framework.Timing; 10using osuTK; 11 12namespace osu.Framework.Benchmarks 13{ 14 public class BenchmarkTransform : BenchmarkTest 15 { 16 private Drawable target; 17 18 public override void SetUp() 19 { 20 base.SetUp(); 21 22 target = new TestBox { Clock = new FramedClock() }; 23 } 24 25 [Benchmark] 26 public Transform CreateSingleBlank() => new TestTransform(); 27 28 [Benchmark] 29 public void CreateSequenceThenClearAfter() 30 { 31 target.FadeIn(1000, Easing.OutQuint) 32 .Then().FadeOut(1000) 33 .Then().FadeOut(1000) 34 .Then().FadeOut(1000) 35 .Then().FadeOut(1000) 36 .Then().FadeOut(1000) 37 .Then().FadeOut(1000) 38 .Then().FadeOut(1000) 39 .Then().FadeOut(1000) 40 .Then().FadeOut(1000) 41 .Then().FadeOut(1000); 42 43 target.ClearTransformsAfter(5000); 44 } 45 46 [Benchmark] 47 public void Expiry() 48 { 49 target.FadeIn(1000, Easing.OutQuint) 50 .ScaleTo(2, 1000, Easing.OutQuint) 51 .RotateTo(2, 1000, Easing.OutQuint); 52 53 for (int i = 0; i < 1000; i++) 54 target.Expire(); 55 56 target.ClearTransforms(); 57 } 58 59 [Benchmark] 60 public void CreateSequenceWithDefaultEasing() 61 { 62 target.FadeIn(1000, Easing.OutQuint) 63 .Then().FadeOut(500) 64 .Then().ScaleTo(new Vector2(2), 500, Easing.OutQuint); 65 target.ClearTransforms(); 66 } 67 68 [Benchmark] 69 public void ApplySequenceWithDefaultEasing() 70 { 71 target.FadeIn(1000, Easing.OutQuint); 72 target.ApplyTransformsAt(double.MaxValue); 73 target.ClearTransforms(); 74 } 75 76 [Benchmark] 77 public void CreateSequenceWithValueEasing() 78 { 79 target.FadeIn(1000, new ValueEasingFunction()) 80 .Then().FadeOut(500, new ValueEasingFunction()) 81 .Then().ScaleTo(new Vector2(2), 500, new ValueEasingFunction()); 82 target.ClearTransforms(); 83 } 84 85 [Benchmark] 86 public void ApplySequenceWithValueEasing() 87 { 88 target.FadeIn(1000, new ValueEasingFunction()); 89 target.ApplyTransformsAt(double.MaxValue); 90 target.ClearTransforms(); 91 } 92 93 [Benchmark] 94 public void CreateSequenceWithReferenceEasing() 95 { 96 target.FadeIn(1000, new ReferenceEasingFunction()) 97 .Then().FadeOut(500, new ReferenceEasingFunction()) 98 .Then().ScaleTo(new Vector2(2), 500, new ReferenceEasingFunction()); 99 target.ClearTransforms(); 100 } 101 102 [Benchmark] 103 public void ApplySequenceWithReferenceEasing() 104 { 105 target.FadeIn(1000, new ReferenceEasingFunction()); 106 target.ApplyTransformsAt(double.MaxValue); 107 target.ClearTransforms(); 108 } 109 110 private readonly struct ValueEasingFunction : IEasingFunction 111 { 112 public double ApplyEasing(double time) => 0; 113 } 114 115 private class ReferenceEasingFunction : IEasingFunction 116 { 117 public double ApplyEasing(double time) => 0; 118 } 119 120 private class TestBox : Box 121 { 122 public override bool RemoveCompletedTransforms => false; 123 } 124 125 private class TestTransform : Transform<float, Box> 126 { 127 public override string TargetMember => throw new NotImplementedException(); 128 129 protected override void Apply(Box d, double time) 130 { 131 throw new NotImplementedException(); 132 } 133 134 protected override void ReadIntoStartValue(Box d) 135 { 136 throw new NotImplementedException(); 137 } 138 } 139 } 140}