diff --git a/Assets/Tests/InputSystem/CorePerformanceTests.cs b/Assets/Tests/InputSystem/CorePerformanceTests.cs index e5480672bd..5d7d8ac230 100644 --- a/Assets/Tests/InputSystem/CorePerformanceTests.cs +++ b/Assets/Tests/InputSystem/CorePerformanceTests.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using UnityEngine.InputSystem; using UnityEngine.InputSystem.LowLevel; @@ -1100,4 +1101,103 @@ public void Performance_OptimizedControls_ReadingPose4kTimes(OptimizationTestTyp } #endif + + #if UNITY_2022_3_OR_NEWER + + // All the profiler markers in the package code. + // Needed for the tests below. + string[] allInputSystemProfilerMarkers = + { + "InputUpdate", + "InputSystem.onBeforeUpdate", + "InputSystem.onAfterUpdate", + "PreUpdate.NewInputUpdate", + "PreUpdate.InputForUIUpdate", + "FixedUpdate.NewInputFixedUpdate" + }; + + [PrebuildSetup(typeof(ProjectWideActionsBuildSetup))] + [PostBuildCleanup(typeof(ProjectWideActionsBuildSetup))] + [UnityTest, Performance] + [Category("Performance")] + public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkers_FPS() + { + var keyboard = InputSystem.AddDevice(); + var mouse = InputSystem.AddDevice(); + + var moveAction = InputSystem.actions.FindAction("Move"); + var lookAction = InputSystem.actions.FindAction("Look"); + var attackAction = InputSystem.actions.FindAction("Attack"); + var jumpAction = InputSystem.actions.FindAction("Jump"); + var sprintAction = InputSystem.actions.FindAction("Sprint"); + + int performedCallCount = 0; + + moveAction.performed += context => { + performedCallCount++; + }; + + lookAction.performed += context => { + performedCallCount++; + }; + + attackAction.performed += context => { + performedCallCount++; + }; + + jumpAction.performed += context => { + performedCallCount++; + }; + + sprintAction.performed += context => { + performedCallCount++; + }; + + using (Measure.ProfilerMarkers(allInputSystemProfilerMarkers)) + { + Press(keyboard.wKey, queueEventOnly: true); + + for (int i = 0; i < 500; ++i) + { + if (i % 60 == 0) + { + PressAndRelease(keyboard.aKey, queueEventOnly: true); + PressAndRelease(keyboard.sKey, queueEventOnly: true); + PressAndRelease(keyboard.dKey, queueEventOnly: true); + + PressAndRelease(keyboard.leftShiftKey, queueEventOnly: true); + + PressAndRelease(keyboard.spaceKey, queueEventOnly: true); + } + + Click(mouse.leftButton, queueEventOnly: true); + + //mouse movements for higher polling mice + for (int j = 0; j < 99; ++j) + { + Move(mouse.position, new Vector2(i + j, i + j), queueEventOnly: true); + } + + InputSystem.Update(); + + yield return null; + } + } + } + + [PrebuildSetup(typeof(ProjectWideActionsBuildSetup))] + [PostBuildCleanup(typeof(ProjectWideActionsBuildSetup))] + [UnityTest, Performance] + [Category("Performance")] + public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkers_DoingNothing() + { + yield return Measure.Frames() + .WarmupCount(30) + .DontRecordFrametime() + .MeasurementCount(500) + .ProfilerMarkers(allInputSystemProfilerMarkers) + .Run(); + } + + #endif }