-
-
Notifications
You must be signed in to change notification settings - Fork 983
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf167b9
commit 8bb28b3
Showing
57 changed files
with
1,137 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,117 @@ | ||
# Baseline | ||
|
||
In order to scale your results, you need to mark one of your benchmark methods as a baseline. Only one method in class can have `Baseline = true` applied. | ||
In order to scale your results, you can mark a benchmark method or a job as a baseline. | ||
Let's learn this feature by examples. | ||
|
||
## Example | ||
## Example 1: Methods | ||
|
||
You can mark a method as a baseline with the help of `[Benchmark(Baseline = true)]`. | ||
|
||
```cs | ||
public class Sleeps | ||
{ | ||
[Benchmark] | ||
public void Time50() | ||
{ | ||
Thread.Sleep(50); | ||
} | ||
public void Time50() => Thread.Sleep(50); | ||
|
||
[Benchmark(Baseline = true)] | ||
public void Time100() | ||
{ | ||
Thread.Sleep(100); | ||
} | ||
public void Time100() => Thread.Sleep(100); | ||
|
||
[Benchmark] | ||
public void Time150() | ||
{ | ||
Thread.Sleep(150); | ||
} | ||
public void Time150() => Thread.Sleep(150); | ||
} | ||
``` | ||
|
||
As a result, you will have additional column in the summary table: | ||
As a result, you will have additional `Scaled` column in the summary table: | ||
|
||
```ini | ||
BenchmarkDotNet=v0.9.0.0 | ||
OS=Microsoft Windows NT 6.2.9200.0 | ||
Processor=Intel(R) Core(TM) i7-4810MQ CPU @ 2.80GHz, ProcessorCount=8 | ||
Frequency=2728067 ticks, Resolution=366.5599 ns | ||
HostCLR=MS.NET 4.0.30319.42000, Arch=64-bit RELEASE [RyuJIT] | ||
BenchmarkDotNet=v0.10.12, OS=Windows 10 Redstone 3 [1709, Fall Creators Update] (10.0.16299.192) | ||
Processor=Intel Core i7-6700HQ CPU 2.60GHz (Skylake), ProcessorCount=8 | ||
Frequency=2531249 Hz, Resolution=395.0619 ns, Timer=TSC | ||
.NET Core SDK=2.0.3 | ||
[Host] : .NET Core 2.0.3 (Framework 4.6.25815.02), 64bit RyuJIT | ||
DefaultJob : .NET Core 2.0.3 (Framework 4.6.25815.02), 64bit RyuJIT | ||
``` | ||
|
||
| Method | Mean | Error | StdDev | Scaled | | ||
|-------- |----------:|----------:|----------:|-------:| | ||
| Time50 | 50.46 ms | 0.0779 ms | 0.0729 ms | 0.50 | | ||
| Time100 | 100.39 ms | 0.0762 ms | 0.0713 ms | 1.00 | | ||
| Time150 | 150.48 ms | 0.0986 ms | 0.0922 ms | 1.50 | | ||
|
||
|
||
## Example 2: Methods with categories | ||
|
||
Type=Sleeps Mode=Throughput | ||
The only way to have several baselines in the same class is to separate them by categories | ||
and mark the class with `[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]`. | ||
|
||
```cs | ||
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)] | ||
[CategoriesColumn] | ||
public class Sleeps | ||
{ | ||
[BenchmarkCategory("Fast"), Benchmark(Baseline = true)] | ||
public void Time50() => Thread.Sleep(50); | ||
|
||
[BenchmarkCategory("Fast"), Benchmark] | ||
public void Time100() => Thread.Sleep(100); | ||
|
||
[BenchmarkCategory("Slow"), Benchmark(Baseline = true)] | ||
public void Time550() => Thread.Sleep(550); | ||
|
||
[BenchmarkCategory("Slow"), Benchmark] | ||
public void Time600() => Thread.Sleep(600); | ||
} | ||
``` | ||
|
||
```ini | ||
BenchmarkDotNet=v0.10.12, OS=Windows 10 Redstone 3 [1709, Fall Creators Update] (10.0.16299.192) | ||
Processor=Intel Core i7-6700HQ CPU 2.60GHz (Skylake), ProcessorCount=8 | ||
Frequency=2531249 Hz, Resolution=395.0619 ns, Timer=TSC | ||
.NET Core SDK=2.0.3 | ||
[Host] : .NET Core 2.0.3 (Framework 4.6.25815.02), 64bit RyuJIT | ||
DefaultJob : .NET Core 2.0.3 (Framework 4.6.25815.02), 64bit RyuJIT | ||
``` | ||
|
||
Method | Median | StdDev | Scaled | ||
-------- |------------ |---------- |------- | ||
Time100 | 100.2640 ms | 0.1238 ms | 1.00 | ||
Time150 | 150.2093 ms | 0.1034 ms | 1.50 | ||
Time50 | 50.2509 ms | 0.1153 ms | 0.50 | ||
| Method | Categories | Mean | Error | StdDev | Scaled | | ||
|-------- |----------- |----------:|----------:|----------:|-------:| | ||
| Time50 | Fast | 50.46 ms | 0.0745 ms | 0.0697 ms | 1.00 | | ||
| Time100 | Fast | 100.47 ms | 0.0955 ms | 0.0893 ms | 1.99 | | ||
| | | | | | | | ||
| Time550 | Slow | 550.48 ms | 0.0525 ms | 0.0492 ms | 1.00 | | ||
| Time600 | Slow | 600.45 ms | 0.0396 ms | 0.0331 ms | 1.09 | | ||
|
||
|
||
## Example 3: Jobs | ||
|
||
If you want to compare several runtime configuration, | ||
you can mark one of your jobs with `isBaseline = true`. | ||
|
||
```cs | ||
[ClrJob(isBaseline: true)] | ||
[MonoJob] | ||
[CoreJob] | ||
public class RuntimeCompetition | ||
{ | ||
[Benchmark] | ||
public int SplitJoin() => string.Join(",", new string[1000]).Split(',').Length; | ||
} | ||
``` | ||
|
||
```ini | ||
BenchmarkDotNet=v0.10.12, OS=Windows 10 Redstone 3 [1709, Fall Creators Update] (10.0.16299.192) | ||
Processor=Intel Core i7-6700HQ CPU 2.60GHz (Skylake), ProcessorCount=8 | ||
Frequency=2531249 Hz, Resolution=395.0619 ns, Timer=TSC | ||
.NET Core SDK=2.0.3 | ||
[Host] : .NET Core 2.0.3 (Framework 4.6.25815.02), 64bit RyuJIT | ||
Job-MXFYPZ : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2600.0 | ||
Core : .NET Core 2.0.3 (Framework 4.6.25815.02), 64bit RyuJIT | ||
Mono : Mono 5.4.0 (Visual Studio), 64bit | ||
``` | ||
|
||
Method | Runtime | Mean | Error | StdDev | Scaled | ScaledSD | | ||
---------- |-------- |---------:|----------:|----------:|-------:|---------:| | ||
SplitJoin | Clr | 19.42 us | 0.2447 us | 0.1910 us | 1.00 | 0.00 | | ||
SplitJoin | Core | 13.00 us | 0.2183 us | 0.1935 us | 0.67 | 0.01 | | ||
SplitJoin | Mono | 39.14 us | 0.7763 us | 1.3596 us | 2.02 | 0.07 | | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/BenchmarkDotNet.Core/Attributes/Columns/IsBaselineColumnAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using BenchmarkDotNet.Columns; | ||
using BenchmarkDotNet.Mathematics; | ||
|
||
namespace BenchmarkDotNet.Attributes.Columns | ||
{ | ||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)] | ||
public class IsBaselineColumnAttribute : ColumnConfigBaseAttribute | ||
{ | ||
public IsBaselineColumnAttribute() : base(IsBaselineColumn.Default) { } | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/BenchmarkDotNet.Core/Attributes/Columns/LogicalGroupColumnAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using BenchmarkDotNet.Columns; | ||
using BenchmarkDotNet.Mathematics; | ||
|
||
namespace BenchmarkDotNet.Attributes.Columns | ||
{ | ||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)] | ||
public class LogicalGroupColumnAttribute : ColumnConfigBaseAttribute | ||
{ | ||
public LogicalGroupColumnAttribute() : base(LogicalGroupColumn.Default) { } | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/BenchmarkDotNet.Core/Attributes/GroupBenchmarksByAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using BenchmarkDotNet.Configs; | ||
using JetBrains.Annotations; | ||
|
||
namespace BenchmarkDotNet.Attributes | ||
{ | ||
[PublicAPI] | ||
public class GroupBenchmarksByAttribute: Attribute, IConfigSource | ||
{ | ||
public IConfig Config { get; } | ||
|
||
// CLS-Compliant Code requires a constuctor without an array in the argument list | ||
protected GroupBenchmarksByAttribute() | ||
{ | ||
Config = ManualConfig.CreateEmpty(); | ||
} | ||
|
||
public GroupBenchmarksByAttribute(params BenchmarkLogicalGroupRule[] rules) | ||
{ | ||
Config = ManualConfig.CreateEmpty().With(rules); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.