docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Performance Testing Package for Unity Test Framework

    The Unity Performance Testing Package extends Unity Test Framework with performance testing capabilities. It provides an API and test case decorators for taking measurements/samples of Unity profiler markers, and other custom metrics, in the Unity Editor and built players. It also collects configuration metadata that is useful for comparing data across different hardware and configurations, such as build and player settings.

    The Performance Testing Package is intended for use with the Unity Test Framework. You should be familiar with how to create and run tests as described in the Unity Test Framework documentation.

    Note: When tests are run with Unity Test Framework, a development player is always built to support communication between the editor and player, effectively overriding the development build setting from the build settings UI or scripting API.

    Installing the Performance Testing Package

    Install the Performance Testing Package package using one of the following methods:

    • Add the package by installing from a Git URL.
    • Add the package as a dependency to the project manifest.

    Example:

    1. Open the manifest.json file for your Unity project (located in the YourProject/Packages directory) in a text editor.
    2. Add "com.unity.test-framework.performance": "3.0.3", to the dependencies.
    3. Save the manifest.json file.
    4. Verify the Performance Testing Package is now installed by opening the Unity Package Manager window.

    When the package is installed, add a reference to Unity.PerformanceTesting in your assembly definition to access the performance testing APIs.

    Performance test example01

    Unity version compatibility

    Unity releases can often include changes that break compatibility with the Performance Testing Package, so we cannot currently guarantee latest package version compatability with every Unity version. The table below shows which version of the package is compatible with which Unity release streams.

    Unity stream Package version
    2023.2 3.0.3
    2023.1 3.0.3
    2022.2 3.0.3
    2022.1 3.0.3
    2021.3 3.0.3
    2020.3 3.0.3
    2019.4 2.8.1-preview

    Tips

    Project settings

    • Remove all but one of the Quality level settings in Project Settings > Quality. Otherwise, you may have different configurations when running on different platforms. If you require different settings per platform then make sure they are being set as expected.
    • Disable VSync under Project Settings > Quality. Some platforms like Android have a forced VSync and this will not be possible.
    • Disable HW Reporting PlayerSettings -> Other -> Disable HW Reporting.
    • Remove camera and run in batchmode if you are not measuring rendering.

    Generating assets

    Use IPrebuildSetup attribute when you need to generate assets. Place assets in Resources or StreamingAssets folders, scenes can be placed anywhere in the project, but should be added to build settings.

    Example 1: IPrebuildSetup implementation

    public class TestsWithPrebuildStep : IPrebuildSetup
    {
        public void Setup()
        {
            // this code is executed before entering playmode or the player is executed
        }
    }
    
    public class MyAmazingPerformanceTest
    {
        [Test, Performance]
        [PrebuildSetup(typeof(TestsWithPrebuildStep))]
        public void Test()
        {
            ...
        }
    }
    

    When loading scenes in IPrebuildSetup you have to use LoadSceneMode.Additive.

    Example 2: Using EditorSceneManager to create new scenes additively, save and add them to build settings.

    private static string m_ArtifactsPath = "Assets/Artifacts/";
    
    public static Scene NewScene(NewSceneSetup setup)
    {
        Scene scene = EditorSceneManager.NewScene(setup, NewSceneMode.Additive);
        EditorSceneManager.SetActiveScene(scene);
        return scene;
    }
    
    public static void SaveScene(Scene scene, string name, bool closeScene = true)
    {
        EditorSceneManager.SaveScene(scene, GetScenePath(name));
    
        if (closeScene)
        {
            foreach (var sceneSetting in EditorBuildSettings.scenes)
                if (sceneSetting.path == GetScenePath((name)))
                    return;
    
            EditorSceneManager.CloseScene(scene, true);
            EditorSceneManager.SetActiveScene(EditorSceneManager.GetSceneAt(0));
    
            var newListOfScenes = new List<EditorBuildSettingsScene>();
            newListOfScenes.Add(new EditorBuildSettingsScene(GetScenePath(name), true));
            newListOfScenes.AddRange(EditorBuildSettings.scenes);
            EditorBuildSettings.scenes = newListOfScenes.ToArray();
        }
    }
    
    public static string GetScenePath(string name)
    {
        return m_ArtifactsPath + name + ".unity";
    }
    

    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • Installing the Performance Testing Package
    • Unity version compatibility
    • Tips
      • Project settings
      • Generating assets
        • Example 1: IPrebuildSetup implementation
        • Example 2: Using EditorSceneManager to create new scenes additively, save and add them to build settings.
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)