Course contentsShow
← Unity Game Development
Lesson 721 of 82811. Performance and Data PersistenceFree lesson

Establishing Performance Baselines with the Profiler

Learn to capture and analyze real-time CPU performance data to identify frame rate drops and stuttering in your game scene.

In this lesson, you will learn how to capture and analyze real-time CPU performance data to establish a solid baseline for identifying frame rate drops and stuttering.

The Importance of a Baseline

Before you can optimize, you must define "normal." A performance baseline is a snapshot of your game’s frame time and CPU usage in a stable, representative scene. Without this, you are merely guessing which systems are causing spikes. By establishing a baseline, you gain the ability to spot "hiccups"—those momentary jumps in frame time that players experience as stuttering.

Capturing the Data

To begin, open the Profiler (Window > Analysis > Profiler) and ensure the CPU Usage module is enabled. For an accurate baseline, avoid testing in the Editor’s "Maximize on Play" mode, as the Editor overhead distorts results. Instead, build your project as a Development Build to get closer to the actual hardware performance.

  1. Run the scene: Let your game run for at least 30 seconds to allow background processes and garbage collection to settle.
  2. Record: Click the Record button and play through a typical gameplay segment.
  3. Analyze: Look for high-amplitude "spikes" in the CPU Usage timeline. Click on a specific spike to freeze the frame and inspect the Hierarchy view.

Interpreting the Results

When you examine the Hierarchy view, focus on the Total % column to see which operations consume the most time. If your Camera.Render takes 12ms and suddenly spikes to 25ms, you’ve identified a frame rate drop. You can then toggle between the Hierarchy and Timeline views to see exactly what triggered that spike—perhaps a heavy Update() call in a script or a sudden surge in shadow updates.

If you want to manually mark specific segments of code to monitor their impact on your baseline, wrap them in the Profiler.BeginSample and Profiler.EndSample tags:

void Update() {
    Profiler.BeginSample("MyCustomCalculation");
    // Heavy math or complex logic
    PerformComplexity();
    Profiler.EndSample();
}

By identifying the "floor" (your average, stable frame time) and the "ceiling" (your worst spikes), you create a benchmark to test future optimizations against.

Key Takeaway: A performance baseline turns subjective "stuttering" into objective data, allowing you to isolate and eliminate the specific processes causing frame rate instability.