docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class MethodMeasurement

    Used as a helper class to sample execution time of methods. Uses fluent pattern to build and needs to be executed with Run method.

    Inheritance
    object
    MethodMeasurement
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Unity.PerformanceTesting.Measurements
    Assembly: Unity.PerformanceTesting.dll
    Syntax
    public class MethodMeasurement

    Constructors

    MethodMeasurement(Action)

    Initializes a method measurement.

    Declaration
    public MethodMeasurement(Action action)
    Parameters
    Type Name Description
    Action action

    Method to be measured.

    Methods

    CleanUp(Action)

    Used to provide a cleanup method which will not be measured.

    Declaration
    public MethodMeasurement CleanUp(Action action)
    Parameters
    Type Name Description
    Action action

    Cleanup method to execute.

    Returns
    Type Description
    MethodMeasurement

    An updated instance of the MethodMeasurement to be used in fluent syntax.

    DynamicMeasurementCount(double, ConfidenceLevel, OutlierMode)

    Dynamically find a suitable measurement count based on the margin of error of the samples. The measurements will stop once a certain amount of samples (specified by a confidence interval) falls within an acceptable error range from the result (defined by a relative error of the mean).

    Declaration
    public MethodMeasurement DynamicMeasurementCount(double maxRelativeError, ConfidenceLevel confidenceLevel = ConfidenceLevel.L99, OutlierMode outlierMode = OutlierMode.Remove)
    Parameters
    Type Name Description
    double maxRelativeError

    The maximum relative error of the mean that the margin of error must fall into.

    ConfidenceLevel confidenceLevel

    The confidence interval which will be used to calculate the margin of error.

    OutlierMode outlierMode

    Outlier mode allows to include or exclude outliers when evaluating the stop criterion.

    Returns
    Type Description
    MethodMeasurement

    An updated instance of the MethodMeasurement to be used in fluent syntax.

    DynamicMeasurementCount(OutlierMode)

    Dynamically find a suitable measurement count based on the margin of error of the samples. The measurements will stop once a certain amount of samples (specified by a confidence interval) falls within an acceptable error range from the result (defined by a relative error of the mean). A default margin of error range of 2% and a default confidence interval of 99% will be used.

    Declaration
    public MethodMeasurement DynamicMeasurementCount(OutlierMode outlierMode = OutlierMode.Remove)
    Parameters
    Type Name Description
    OutlierMode outlierMode

    Outlier mode allows to include or exclude outliers when evaluating the stop criterion.

    Returns
    Type Description
    MethodMeasurement

    An updated instance of the MethodMeasurement to be used in fluent syntax.

    GC()

    Enables recording of garbage collector calls.

    Declaration
    public MethodMeasurement GC()
    Returns
    Type Description
    MethodMeasurement

    An updated instance of the MethodMeasurement to be used in fluent syntax.

    IterationsPerMeasurement(int)

    Specifies the amount of method executions for a single measurement.

    Declaration
    public MethodMeasurement IterationsPerMeasurement(int count)
    Parameters
    Type Name Description
    int count

    Count of method executions.

    Returns
    Type Description
    MethodMeasurement

    An updated instance of the MethodMeasurement to be used in fluent syntax.

    MeasurementCount(int)

    Specifies the number of measurements to take.

    Declaration
    public MethodMeasurement MeasurementCount(int count)
    Parameters
    Type Name Description
    int count

    Count of measurements to take.

    Returns
    Type Description
    MethodMeasurement

    An updated instance of the MethodMeasurement to be used in fluent syntax.

    ProfilerMarkers(params string[])

    Will record provided profiler markers once per frame.

    Declaration
    public MethodMeasurement ProfilerMarkers(params string[] profilerMarkerNames)
    Parameters
    Type Name Description
    string[] profilerMarkerNames

    Profiler marker names as in profiler window.

    Returns
    Type Description
    MethodMeasurement

    An updated instance of the MethodMeasurement to be used in fluent syntax.

    ProfilerMarkers(params SampleGroup[])

    Will record provided profiler markers once per frame with additional control over the SampleUnit.

    Declaration
    public MethodMeasurement ProfilerMarkers(params SampleGroup[] sampleGroups)
    Parameters
    Type Name Description
    SampleGroup[] sampleGroups

    List of SampleGroups where a name matches the profiler marker and desired SampleUnit.

    Returns
    Type Description
    MethodMeasurement

    An updated instance of the MethodMeasurement to be used in fluent syntax.

    Run()

    Executes the measurement with given parameters. When MeasurementCount is not provided, a probing method will run to determine desired measurement counts.

    Declaration
    public void Run()

    SampleGroup(string)

    Overrides the default SampleGroup of "Time".

    Declaration
    public MethodMeasurement SampleGroup(string name)
    Parameters
    Type Name Description
    string name

    Desired name for measurement SampleGroup.

    Returns
    Type Description
    MethodMeasurement

    An updated instance of the MethodMeasurement to be used in fluent syntax.

    SampleGroup(SampleGroup)

    Overrides the default SampleGroup.

    Declaration
    public MethodMeasurement SampleGroup(SampleGroup sampleGroup)
    Parameters
    Type Name Description
    SampleGroup sampleGroup

    SampleGroup with your desired name and unit.

    Returns
    Type Description
    MethodMeasurement

    An updated instance of the MethodMeasurement to be used in fluent syntax.

    SetUp(Action)

    Used to provide a setup method which will run before the measurement.

    Declaration
    public MethodMeasurement SetUp(Action action)
    Parameters
    Type Name Description
    Action action

    Setup method to execute.

    Returns
    Type Description
    MethodMeasurement

    An updated instance of the MethodMeasurement to be used in fluent syntax.

    WarmupCount(int)

    Count of times to execute before measurements are collected. If unspecified, a default warmup will be assigned.

    Declaration
    public MethodMeasurement WarmupCount(int count)
    Parameters
    Type Name Description
    int count

    Count of warmup iterations to execute.

    Returns
    Type Description
    MethodMeasurement

    An updated instance of the MethodMeasurement to be used in fluent syntax.

    In This Article
    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)