1
- using BenchmarkDotNet . Attributes ;
2
- using BenchmarkDotNet . Columns ;
1
+ using BenchmarkDotNet . Columns ;
3
2
using BenchmarkDotNet . Configs ;
4
- using BenchmarkDotNet . Jobs ;
5
3
using BenchmarkDotNet . Reports ;
6
- using BenchmarkDotNet . Running ;
4
+ using BenchmarkDotNet . Tests . Mocks ;
5
+ using System ;
7
6
using System . Linq ;
8
- using System . Threading ;
9
7
using Xunit ;
10
8
11
9
namespace BenchmarkDotNet . IntegrationTests
@@ -15,39 +13,21 @@ public class AutomaticBaselineTests
15
13
[ Fact ]
16
14
public void AutomaticBaselineSelectionIsCorrect ( )
17
15
{
18
- var config = CreateConfig ( ) ;
19
-
20
- var summary = BenchmarkRunner . Run < BaselineSample > ( ) ;
16
+ var config = ManualConfig . CreateEmpty ( )
17
+ . AddColumnProvider ( DefaultColumnProviders . Instance )
18
+ . WithAutomaticBaseline ( AutomaticBaselineMode . Fastest ) ;
21
19
20
+ var summary = MockFactory . CreateSummary ( config , hugeSd : true , Array . Empty < Metric > ( ) ) ;
22
21
var table = summary . GetTable ( SummaryStyle . Default ) ;
23
- var column = table . Columns . Single ( c => c . Header == "Ratio" ) ;
24
- Assert . Equal ( 2 , column . Content . Length ) ;
25
- Assert . Equal ( 1.0 , double . Parse ( column . Content [ 1 ] ) ) ; // Ratio of TwoMilliseconds
26
- Assert . True ( double . Parse ( column . Content [ 0 ] ) > 1.0 ) ; // Ratio of TwoHundredMilliseconds
27
- }
22
+ var method = table . Columns . Single ( c => c . Header == "Method" ) ;
23
+ var mean = table . Columns . Single ( c => c . Header == "Mean" ) ;
24
+ var ratio = table . Columns . Single ( c => c . Header == "Ratio" ) ;
28
25
29
- [ AutomaticBaseline ( AutomaticBaselineMode . Fastest ) ]
30
- public class BaselineSample
31
- {
32
- [ Benchmark ]
33
- public void TwoHundredMilliseconds ( )
34
- {
35
- Thread . Sleep ( 200 ) ;
36
- }
37
-
38
- [ Benchmark ]
39
- public void TwoMilliseconds ( )
40
- {
41
- Thread . Sleep ( 2 ) ;
42
- }
26
+ Assert . Equal ( 2 , method . Content . Length ) ;
27
+ Assert . Equal ( nameof ( MockFactory . MockBenchmarkClass . Foo ) , method . Content [ 0 ] ) ;
28
+ Assert . Equal ( 1.0 , double . Parse ( ratio . Content [ 0 ] ) ) ; // A faster one, see measurements in MockFactory.cs
29
+ Assert . Equal ( nameof ( MockFactory . MockBenchmarkClass . Bar ) , method . Content [ 1 ] ) ;
30
+ Assert . Equal ( 1.5 , double . Parse ( ratio . Content [ 1 ] ) ) ;
43
31
}
44
-
45
- private IConfig CreateConfig ( )
46
- => ManualConfig . CreateEmpty ( )
47
- . AddJob ( Job . ShortRun
48
- . WithEvaluateOverhead ( false ) // no need to run idle for this test
49
- . WithWarmupCount ( 0 ) // don't run warmup to save some time for our CI runs
50
- . WithIterationCount ( 1 ) ) // single iteration is enough for us
51
- . AddColumnProvider ( DefaultColumnProviders . Instance ) ;
52
32
}
53
33
}
0 commit comments