1- using BenchmarkDotNet . Attributes ;
2- using BenchmarkDotNet . Columns ;
1+ using BenchmarkDotNet . Columns ;
32using BenchmarkDotNet . Configs ;
4- using BenchmarkDotNet . Jobs ;
53using BenchmarkDotNet . Reports ;
6- using BenchmarkDotNet . Running ;
4+ using BenchmarkDotNet . Tests . Mocks ;
5+ using System ;
76using System . Linq ;
8- using System . Threading ;
97using Xunit ;
108
119namespace BenchmarkDotNet . IntegrationTests
@@ -15,39 +13,21 @@ public class AutomaticBaselineTests
1513 [ Fact ]
1614 public void AutomaticBaselineSelectionIsCorrect ( )
1715 {
18- var config = CreateConfig ( ) ;
19-
20- var summary = BenchmarkRunner . Run < BaselineSample > ( ) ;
16+ var config = ManualConfig . CreateEmpty ( )
17+ . AddColumnProvider ( DefaultColumnProviders . Instance )
18+ . WithAutomaticBaseline ( AutomaticBaselineMode . Fastest ) ;
2119
20+ var summary = MockFactory . CreateSummary ( config , hugeSd : true , Array . Empty < Metric > ( ) ) ;
2221 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" ) ;
2825
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 ] ) ) ;
4331 }
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 ) ;
5232 }
5333}
0 commit comments