A game framework written with osu! in mind.
at master 1.7 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.Collections.Generic; 5using BenchmarkDotNet.Attributes; 6using osu.Framework.Input.StateChanges; 7using osu.Framework.Input.StateChanges.Events; 8using osu.Framework.Input.States; 9using osuTK.Input; 10 11namespace osu.Framework.Benchmarks 12{ 13 [MemoryDiagnoser] 14 public class BenchmarkButtonInput 15 { 16 [Arguments(1)] 17 [Arguments(5)] 18 [Arguments(10)] 19 [Arguments(50)] 20 [Benchmark] 21 public KeyboardKeyInput FromTwoStates(int count) 22 { 23 var state1 = new ButtonStates<Key>(); 24 var state2 = new ButtonStates<Key>(); 25 26 for (int i = 0; i < count; i++) 27 state1.SetPressed((Key)i, true); 28 29 for (int i = count; i < 2 * count; i++) 30 state2.SetPressed((Key)i, true); 31 32 return new KeyboardKeyInput(state1, state2); 33 } 34 35 [Benchmark] 36 public InputState Apply() 37 { 38 var entries = new List<ButtonInputEntry<Key>>(); 39 40 for (int i = 0; i < 10; i++) 41 entries.Add(new ButtonInputEntry<Key>((Key)i, true)); 42 43 var input = new KeyboardKeyInput(entries); 44 var state = new InputState(); 45 input.Apply(state, new NullStateChangeHandler()); 46 47 return state; 48 } 49 50 private struct NullStateChangeHandler : IInputStateChangeHandler 51 { 52 public void HandleInputStateChange(InputStateChangeEvent inputStateChange) 53 { 54 } 55 } 56 } 57}