Tip
Try also online.
public abstract class PerformanceTestBase<TDelegate, TResult> : PerformanceTestBase
where TDelegate : Delegate
Public MustInherit Class PerformanceTestBase(Of TDelegate As Delegate, TResult)
Inherits PerformanceTestBase
generic<typename TDelegate, typename TResult>
where TDelegate : Delegate
public ref class PerformanceTestBase abstract : public PerformanceTestBase
[<AbstractClassAttribute>]
type PerformanceTestBase<'TDelegate, 'TResult when 'TDelegate : Delegate> =
class
inherit PerformanceTestBase
end
public class RandomizedPerformanceTest<T> : PerformanceTestBase<Func<Random, T>, T>
{
private Random random;
// a fix seed can be specified when initializing the test
public int Seed { get; set; }
protected override T Invoke(Func<Random, T> del) => del.Invoke(random);
// resetting the random instance with the specified seed before executing each case
protected override void OnBeforeCase() => random = new Random(Seed);
}
new RandomizedPerformanceTest<string> { Seed = 0, Iterations = 1_000_000 }
.AddCase(rnd => rnd.NextEnum<ConsoleColor>().ToString(), "Enum.ToString")
.AddCase(rnd => Enum<ConsoleColor>.ToString(rnd.NextEnum<ConsoleColor>()), "Enum<TEnum>.ToString")
.DoTest()
.DumpResults(Console.Out);
PerformanceTestBaseTDelegate, TResult | Initializes a new instance of the PerformanceTestBaseTDelegate, TResult class |
Collect |
Gets or sets whether GC.Collect should be called before running the test cases.
Default value: . (Inherited from PerformanceTestBase) |
CpuAffinity |
Gets or sets the CPU affinity to be used for executing tests. If , or is too large for the executing system, then the affinity is not adjusted for the test.
Default value: null. (Inherited from PerformanceTestBase) |
Iterations |
Gets or sets number of iterations of test cases. If greater than zero, then TestTime is ignored.
Default value: 0. (Inherited from PerformanceTestBase) |
Repeat |
Gets or sets how many times the test cases should be repeated.
Default value: 1. (Inherited from PerformanceTestBase) |
SortBySize |
Gets or sets whether the results should be sorted by the size of the produced result instead of iterations count or time results.
Makes sense only if the test delegate has a return type and the returned value of a test case is always the same for each run.
Default value: . (Inherited from PerformanceTestBase) |
TestName |
Gets or sets the name of the test.
(Inherited from PerformanceTestBase) |
TestTime |
Gets or sets the test duration, in milliseconds, for each test case and the warming-up sessions.
If Iterations is greater than zero, then this property affects only the warm-up time.
Default value: 2000. (Inherited from PerformanceTestBase) |
WarmUp |
Gets or sets whether there is an untested warm-up session before each test.
Its duration equals to TestTime.
Default value: . (Inherited from PerformanceTestBase) |
AddCase |
Adds a test case to the test suit.
See the Examples section of the PerformanceTest class for some examples. |
AsString | Gets the string representation of the specified result. |
DoTest |
Performs the test and returns the test results.
(Overrides PerformanceTestBaseDoTest) |
GetLength |
Gets the length of the result in any unit specified by the GetUnit method.
The base implementation returns element count if TResult is IEnumerable; otherwise, the size of TResult in bytes (which is 4 or 8 bytes for reference types, depending on the platform target). |
GetUnit |
Gets the length unit name of TResult.
The base implementation returns the element name if TResult is IEnumerableT (C# alias name, if applicable); a localized string for item, if TResult is a non-generic IEnumerable; otherwise, a localized string for byte. |
Invoke | Invokes the specified delegate. |
OnAfterCase | Raises the AfterCase event. Called after each repetition of a test case, including the warming-up session. |
OnBeforeCase | Raises the BeforeCase event. Called before each repetition of a test case, including the warming-up session. |
OnInitialize | Raises the Initialize event. This method is called before running the test cases. |
OnTearDown | Raises the TearDown event. Called after running the tests, even after a failure. |
AfterCase | Occurs after each repetition of a test case, including the warming-up session. |
BeforeCase | Occurs before each repetition of a test case, including the warming-up session. |
Initialize | Occurs before running the test cases. |
TearDown | Occurs after running the tests, even after a failure. |
Convert |
Converts an Object specified in the obj parameter to the desired targetType.
See the Examples section of the generic ConvertTTarget(Object, CultureInfo) overload for an example. (Defined by ObjectExtensions) |
ConvertTTarget |
Converts an Object specified in the obj parameter to the desired TTarget.
(Defined by ObjectExtensions) |
In |
Gets whether item is among the elements of set.
See the Examples section of the generic InT(T, T) overload for an example. (Defined by ObjectExtensions) |
TryConvert |
Tries to convert an Object specified in the obj parameter to the desired targetType.
See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example. (Defined by ObjectExtensions) |
TryConvert |
Tries to convert an Object specified in the obj parameter to the desired targetType.
See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example. (Defined by ObjectExtensions) |
TryConvertTTarget |
Tries to convert an Object specified in the obj parameter to the desired TTarget.
See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example. (Defined by ObjectExtensions) |
TryConvertTTarget |
Tries to convert an Object specified in the obj parameter to the desired TTarget.
See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example. (Defined by ObjectExtensions) |