I have a turn-based game with CPU-intensive undo logic that I’m trying to profile. I made an Edit Mode test that runs just fine in Test Runner as a 10-second performance benchmark, but I’d like to be able to run it and (ideally) see info about the run in Profiler → CPU Usage, or anywhere I can look at the CPU time hierarchy.
Since I’m really just trying to benchmark C# code, I’ve tried using the profiling tools in Visual Studio, but the way the .csproj is configured seems to result in all test runs being aborted. Any way I can do this, either inside or outside of the Unity Editor?
You can also try Unity Highlights Profiler Module that displays information on whether your application is meeting its target frame rate and if its performance is bound by the CPU or the GPU, and where to begin investigating potential performance problems.
Starting with Unity 2023.2, it helps you quickly identify app bottlenecks so that you can have an entry point for your new optimization cycle.
This module is not enabled by default, so you will have to:
Open the Profiler window: Window > Analysis > Profiler.
I feel like you have conflicting goals here. If you want to benchmark your C# code, you’d want to be running Performance tests in a built Player with the parts you want to benchmark marked up with ProfilerMarkers.
If you want to see the full hierarchy in Deep Profiling you’re getting distorted performance results due to the overhead of all of your C# code being instrumented for you. You can target the Editor and turn Profiler.enabled on just before the tested code and off after but still won’t be run anything close to a benchmark because it’s not a Player and the code is running with full instrumentation.