using System;
namespace Unity.PerformanceTesting.Benchmark
{
///
/// Mark a class containing performance tests for use in benchmark comparison generation. Each variant defined in the enum Type
/// will be ran and measured for comparison when running benchmarking. The variants in the enum also create mulitple
/// appropriate Performance Test Framework tests for regression testing. See for more information
/// on the enum definition.
///
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public class BenchmarkAttribute : Attribute
{
///
/// Specify the enum Type to form benchmark comparisons around.
///
/// The enum Type which defines variants of a performance test to compare with each other in benchmarking
/// If true, when is called
/// with this `benchmarkComparisonEnum` type, don't include this class of performance in benchmark report generation.
public BenchmarkAttribute(Type benchmarkComparisonEnum, bool ignoreInSuite = false) { }
}
///
/// Mark an enum as defining benchmarking variants.
/// Each variant defined in the enum Type will be ran and measured for comparison when running benchmarking. The variants in the
/// enum also create multiple appropriate Performance Test Framework tests for regression testing.
/// When defining a benchmark, a baseline must also be specified. This can be part of the enum values, or external. Any non-baseline variants meant
/// for benchmarking only and not for Performance Test Framework tests can be defined external to the enum using .
///
[AttributeUsage(AttributeTargets.Enum, AllowMultiple = false, Inherited = false)]
public class BenchmarkComparisonAttribute : Attribute
{
///
/// Mark the enum for use in Benchmark comparisons and specify the enum value which will also serve as the baseline for speed-up calculations
///
/// The enum value, cast to int, to be the baseline
public BenchmarkComparisonAttribute(int baselineEnumValue) { }
///
/// Mark the enum for use in Benchmark comparisons and specify the a non-enum value which will also serve as the baseline for speed-up calculations.
/// This external value will not be included in Performance Test Framework testing.
///
/// The external value, unique from any of the enum values, to be the baseline
/// The string format such as "Native{0}" or "Unsafe{0}" for name formatting in report generation. Only index 0 is supported here.
public BenchmarkComparisonAttribute(int externalBaselineValue, string externalBaselineFormat) { }
}
///
/// Further define a benchmark comparison (see ) which is not defined in the enum and is not a baseline
/// measurement. Some benchmarks may want to compare against multiple other implementations that aren't intended for Performance Test Framework
/// and regression testing, so this provides a means of specifying these.
///
[AttributeUsage(AttributeTargets.Enum, AllowMultiple = true, Inherited = false)]
public class BenchmarkComparisonExternalAttribute : Attribute
{
///
/// Specify the value to include in benchmarking which is not defined by the enum itself. See
///
/// A value unique to both other external values as well as the enum values
/// The string format such as "Native{0}" or "Unsafe{0}" for name formatting in report generation. Only index 0 is supported here.
/// See for more information.
public BenchmarkComparisonExternalAttribute(int externalValue, string externalFormat) { }
}
///
/// Override the display behaviour of benchmarking results. Be default, results are displayed as the median sample in milliseconds with 3 decimal places.
/// This is a global setting which effects any benchmark defined by this enum. See
///
[AttributeUsage(AttributeTargets.Enum, AllowMultiple = false, Inherited = false)]
public class BenchmarkComparisonDisplayAttribute : Attribute
{
///
/// Specify the display configuration for this benchmark.
///
/// Specify the unit type for time measurements, such as milliseconds, seconds, etc. See
/// Specify the decimal places for measurement results. Note this is constant and will fill with 0s if needed.
/// The statistic to display in benchmarking comparisons, such as median, max, etc. See
public BenchmarkComparisonDisplayAttribute(SampleUnit unit, int decimalPlaces, BenchmarkRankingStatistic rankingStatistic) { }
}
///
/// Required with each benchmark enum value. Describes the formatting string for naming benchmarks for this comparison type.
/// For example `BenchmarkName["Native{0}"]` combined with a class named "HashSet" containing performance test/benchmark methods
/// will generate "NativeHashSet" in the benchmark results table header. To override the behaviour of inserting the class name
/// into the {0} format parameter, such as if the class is named "HashSetBenchmarks" and the table header should just insert "HashSet"
/// for the {0} format parameter, use with the class ("HashSetBenchmarks" in this example).
///
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
public class BenchmarkNameAttribute : Attribute
{
///
/// Define the formatting string for an enum value.
///
/// The string format such as "Native{0}" or "Unsafe{0}" for name formatting in report generation. Only index 0 is supported here.
public BenchmarkNameAttribute(string name) { }
}
///
/// Overrides the name used in benchmark report table headers as defined with . By default the name of the class containing tests is used.
///
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public class BenchmarkNameOverrideAttribute : Attribute
{
///
/// Override the name for all benchmark variants.
///
/// The name to be used in place of the class name. See .
public BenchmarkNameOverrideAttribute(string name) { }
///
/// Override the name for a specified benchmark variant.
///
/// The enum defined comparison value ( cast to int or the externally defined
/// comparison value ()
/// The name to be used in place of the class name. See .
public BenchmarkNameOverrideAttribute(int benchmarkComparisonValue, string name) { }
}
///
/// Generate a footnote for this performance test when used in benchmark report generation. This attribute will always insert
/// a footnote describing the parameters in the performance test, sans the benchmark comparison enum. For example:
/// public unsafe void AddGrow(
/// [Values(4, 65536)] int capacity,
/// [Values(1024 * 1024)] int growTo,
/// [Values] BenchmarkContainerType type)
/// {
/// will generate a footnote with "AddGrow(capacity, growTo)" with any use of this attribute on the `AddGrow` method.
///
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class BenchmarkTestFootnoteAttribute : Attribute
{
///
/// Generate a footnote describing the parameter names used in the method.
///
public BenchmarkTestFootnoteAttribute() { }
///
/// Generate a footnote describing the parameters used in the method, as well as a user-defined description.
///
/// The user defined description to follow the automatically generated method parameters
public BenchmarkTestFootnoteAttribute(string description) { }
}
}