Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions Assets/Tests/InputSystem/CorePerformanceTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.LowLevel;
Expand Down Expand Up @@ -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<Keyboard>();
var mouse = InputSystem.AddDevice<Mouse>();

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
}