No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BenchmarkAttributes.cs 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using System;
  2. namespace Unity.PerformanceTesting.Benchmark
  3. {
  4. /// <summary>
  5. /// Mark a class containing performance tests for use in benchmark comparison generation. Each variant defined in the enum Type
  6. /// will be ran and measured for comparison when running benchmarking. The variants in the enum also create mulitple
  7. /// appropriate Performance Test Framework tests for regression testing. See <see cref="BenchmarkComparisonAttribute"/> for more information
  8. /// on the enum definition.
  9. /// </summary>
  10. [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
  11. public class BenchmarkAttribute : Attribute
  12. {
  13. /// <summary>
  14. /// Specify the enum Type to form benchmark comparisons around.
  15. /// </summary>
  16. /// <param name="benchmarkComparisonEnum">The enum Type which defines variants of a performance test to compare with each other in benchmarking</param>
  17. /// <param name="ignoreInSuite">If true, when <see cref="BenchmarkGenerator.GenerateMarkdown(string, Type, string, string, string, string[])"/> is called
  18. /// with this `benchmarkComparisonEnum` type, don't include this class of performance in benchmark report generation.</param>
  19. public BenchmarkAttribute(Type benchmarkComparisonEnum, bool ignoreInSuite = false) { }
  20. }
  21. /// <summary>
  22. /// Mark an enum as defining benchmarking variants.<para />
  23. /// Each variant defined in the enum Type will be ran and measured for comparison when running benchmarking. The variants in the
  24. /// enum also create multiple appropriate Performance Test Framework tests for regression testing.<para />
  25. /// 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
  26. /// for benchmarking only and not for Performance Test Framework tests can be defined external to the enum using <see cref="BenchmarkComparisonExternalAttribute"/>.
  27. /// </summary>
  28. [AttributeUsage(AttributeTargets.Enum, AllowMultiple = false, Inherited = false)]
  29. public class BenchmarkComparisonAttribute : Attribute
  30. {
  31. /// <summary>
  32. /// Mark the enum for use in Benchmark comparisons and specify the enum value which will also serve as the baseline for speed-up calculations
  33. /// </summary>
  34. /// <param name="baselineEnumValue">The enum value, cast to int, to be the baseline</param>
  35. public BenchmarkComparisonAttribute(int baselineEnumValue) { }
  36. /// <summary>
  37. /// 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.
  38. /// This external value will not be included in Performance Test Framework testing.
  39. /// </summary>
  40. /// <param name="externalBaselineValue">The external value, unique from any of the enum values, to be the baseline</param>
  41. /// <param name="externalBaselineFormat">The string format such as "Native{0}" or "Unsafe{0}" for name formatting in report generation. Only index 0 is supported here.</param>
  42. public BenchmarkComparisonAttribute(int externalBaselineValue, string externalBaselineFormat) { }
  43. }
  44. /// <summary>
  45. /// Further define a benchmark comparison (see <see cref="BenchmarkComparisonAttribute"/>) which is not defined in the enum and is not a baseline
  46. /// measurement. Some benchmarks may want to compare against multiple other implementations that aren't intended for Performance Test Framework
  47. /// and regression testing, so this provides a means of specifying these.
  48. /// </summary>
  49. [AttributeUsage(AttributeTargets.Enum, AllowMultiple = true, Inherited = false)]
  50. public class BenchmarkComparisonExternalAttribute : Attribute
  51. {
  52. /// <summary>
  53. /// Specify the value to include in benchmarking which is not defined by the enum itself. See <see cref="BenchmarkComparisonAttribute"/>
  54. /// </summary>
  55. /// <param name="externalValue">A value unique to both other external values as well as the enum values</param>
  56. /// <param name="externalFormat">The string format such as "Native{0}" or "Unsafe{0}" for name formatting in report generation. Only index 0 is supported here.
  57. /// See <see cref="BenchmarkNameAttribute"/> for more information.</param>
  58. public BenchmarkComparisonExternalAttribute(int externalValue, string externalFormat) { }
  59. }
  60. /// <summary>
  61. /// Override the display behaviour of benchmarking results. Be default, results are displayed as the median sample in milliseconds with 3 decimal places.
  62. /// This is a global setting which effects any benchmark defined by this enum. See <see cref="BenchmarkComparisonAttribute"/>
  63. /// </summary>
  64. [AttributeUsage(AttributeTargets.Enum, AllowMultiple = false, Inherited = false)]
  65. public class BenchmarkComparisonDisplayAttribute : Attribute
  66. {
  67. /// <summary>
  68. /// Specify the display configuration for this benchmark.
  69. /// </summary>
  70. /// <param name="unit">Specify the unit type for time measurements, such as milliseconds, seconds, etc. See <see cref="SampleUnit"/></param>
  71. /// <param name="decimalPlaces">Specify the decimal places for measurement results. Note this is constant and will fill with 0s if needed.</param>
  72. /// <param name="rankingStatistic">The statistic to display in benchmarking comparisons, such as median, max, etc. See <see cref="BenchmarkRankingStatistic"/></param>
  73. public BenchmarkComparisonDisplayAttribute(SampleUnit unit, int decimalPlaces, BenchmarkRankingStatistic rankingStatistic) { }
  74. }
  75. /// <summary>
  76. /// Required with each benchmark enum value. Describes the formatting string for naming benchmarks for this comparison type.<para />
  77. /// For example `BenchmarkName["Native{0}"]` combined with a class named "HashSet" containing performance test/benchmark methods
  78. /// will generate "NativeHashSet" in the benchmark results table header. To override the behaviour of inserting the class name
  79. /// into the {0} format parameter, such as if the class is named "HashSetBenchmarks" and the table header should just insert "HashSet"
  80. /// for the {0} format parameter, use <see cref="BenchmarkNameOverrideAttribute"/> with the class ("HashSetBenchmarks" in this example).<para />
  81. /// </summary>
  82. [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
  83. public class BenchmarkNameAttribute : Attribute
  84. {
  85. /// <summary>
  86. /// Define the formatting string for an enum value.
  87. /// </summary>
  88. /// <param name="name">The string format such as "Native{0}" or "Unsafe{0}" for name formatting in report generation. Only index 0 is supported here.</param>
  89. public BenchmarkNameAttribute(string name) { }
  90. }
  91. /// <summary>
  92. /// Overrides the name used in benchmark report table headers as defined with <see cref="BenchmarkNameAttribute"/>. By default the name of the class containing tests is used.
  93. /// </summary>
  94. [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
  95. public class BenchmarkNameOverrideAttribute : Attribute
  96. {
  97. /// <summary>
  98. /// Override the name for all benchmark variants.
  99. /// </summary>
  100. /// <param name="name">The name to be used in place of the class name. See <see cref="BenchmarkNameAttribute"/>.</param>
  101. public BenchmarkNameOverrideAttribute(string name) { }
  102. /// <summary>
  103. /// Override the name for a specified benchmark variant.
  104. /// </summary>
  105. /// <param name="benchmarkComparisonValue">The enum defined comparison value (<see cref="BenchmarkComparisonAttribute"/> cast to int or the externally defined
  106. /// comparison value (<see cref="BenchmarkComparisonExternalAttribute"/>)</param>
  107. /// <param name="name">The name to be used in place of the class name. See <see cref="BenchmarkNameAttribute"/>.</param>
  108. public BenchmarkNameOverrideAttribute(int benchmarkComparisonValue, string name) { }
  109. }
  110. /// <summary>
  111. /// Generate a footnote for this performance test when used in benchmark report generation. This attribute will always insert
  112. /// a footnote describing the parameters in the performance test, sans the benchmark comparison enum. For example:<para />
  113. /// <c>public unsafe void AddGrow(<br />
  114. /// [Values(4, 65536)] int capacity,<br />
  115. /// [Values(1024 * 1024)] int growTo,<br />
  116. /// [Values] BenchmarkContainerType type)<br />
  117. /// {</c><para />
  118. /// will generate a footnote with "AddGrow(capacity, growTo)" with any use of this attribute on the `AddGrow` method.
  119. /// </summary>
  120. [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
  121. public class BenchmarkTestFootnoteAttribute : Attribute
  122. {
  123. /// <summary>
  124. /// Generate a footnote describing the parameter names used in the method.
  125. /// </summary>
  126. public BenchmarkTestFootnoteAttribute() { }
  127. /// <summary>
  128. /// Generate a footnote describing the parameters used in the method, as well as a user-defined description.
  129. /// </summary>
  130. /// <param name="description">The user defined description to follow the automatically generated method parameters</param>
  131. public BenchmarkTestFootnoteAttribute(string description) { }
  132. }
  133. }