Skip to content
Merged
Changes from 7 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
108 changes: 108 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 All @@ -12,6 +13,7 @@
using UnityEngine.InputSystem.Users;
using UnityEngine.InputSystem.Utilities;
using UnityEngine.TestTools;
using static System.Collections.Specialized.BitVector32;

////TODO: add test for domain reload logic

Expand Down Expand Up @@ -1100,4 +1102,110 @@ public void Performance_OptimizedControls_ReadingPose4kTimes(OptimizationTestTyp
}

#endif

#if UNITY_2022_3_OR_NEWER
[PrebuildSetup(typeof(ProjectWideActionsBuildSetup))]
[PostBuildCleanup(typeof(ProjectWideActionsBuildSetup))]
[UnityTest, Performance]
[Category("Performance")]
public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkers_FPS()
{
string[] markers =
{
"InputUpdate",
"InputSystem.onBeforeUpdate",
"InputSystem.onAfterUpdate",
"PreUpdate.NewInputUpdate",
"PreUpdate.InputForUIUpdate",
"FixedUpdate.NewInputFixedUpdate"
};

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(markers))
{
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()
{
string[] markers =
{
"InputUpdate",
"InputSystem.onBeforeUpdate",
"InputSystem.onAfterUpdate",
"PreUpdate.NewInputUpdate",
"PreUpdate.InputForUIUpdate",
"FixedUpdate.NewInputFixedUpdate"
};

yield return Measure.Frames()
.WarmupCount(30)
.DontRecordFrametime()
.MeasurementCount(500)
.ProfilerMarkers(markers)
.Run();
}

#endif
}