Provides extensions over xUnit to author performance tests.
Provides extensions over xUnit to author performance tests.
This repo has been archived, as this project is no longer maintained. We recommend that you use BenchmarkDotNet for your benchmarking needs.
[Benchmark]
void TestMethod()
{
// Any per-test-case setup can go here.
foreach (var iteration in Benchmark.Iterations)
{
// Any per-iteration setup can go here.
using (iteration.StartMeasurement())
{
// Code to be measured goes here.
}
// ...per-iteration cleanup
}
// ...per-test-case cleanup
}The simplest possible benchmark is therefore:
[Benchmark]
void EmptyBenchmark()
{
foreach (var iteration in Benchmark.Iterations)
using (iteration.StartMeasurement())
; //do nothing
}Which can also be written as:
[Benchmark]
void EmptyBenchmark()
{
Benchmark.Iterate(() => { /*do nothing*/ });
}In addition, you can add inner iterations to the code to be measured.
…Once you create an instance of the XunitPerformanceHarness, it comes with a configuration object of type ScenarioConfiguration, which has default values that you can edit to properly apply to your test requirements.
public class ScenarioConfiguration
{
public int Iterations { get; }
public TimeSpan TimeoutPerIteration { get; }
}To control the order of benchmarks executed within a type you need to use an existing xunit feature. All you have to do is to implement a type which implements ITestCaseOrderer interface and configure it by using [TestCaseOrderer] attribute.
Example:
public class DefaultTestCaseOrderer : ITestCaseOrderer
{
public IEnumerable OrderTestCases(IEnumerable testCases) where TTestCase : ITestCase
=> testCases.OrderBy(test => test.DisplayName); // OrderBy provides stable sort ([msdn](https://msdn.microsoft.com/en-us/library/bb534966.aspx))
}
[assembly: TestCaseOrderer("namespace.OrdererTypeName", "assemblyName")]Note: Please make sure that you have provided full type name (with namespace) and the correct assembly name. Wrong configuration ends up with a silent error.
No open issues yet, or sync has not completed.