8
8
using BenchmarkDotNet . Engines ;
9
9
using BenchmarkDotNet . Extensions ;
10
10
using BenchmarkDotNet . Jobs ;
11
- using BenchmarkDotNet . Portability ;
12
11
using BenchmarkDotNet . Reports ;
13
12
using BenchmarkDotNet . Tests . XUnit ;
14
13
using BenchmarkDotNet . Toolchains . InProcess . Emit ;
15
- using Perfolizer . Horology ;
16
14
using Xunit ;
17
15
using Xunit . Abstractions ;
18
16
@@ -23,8 +21,6 @@ public class ExpectedBenchmarkResultsTests : BenchmarkTestExecutor
23
21
// NativeAot takes a long time to build, so not including it in these tests.
24
22
// We also don't test InProcessNoEmitToolchain because it is known to be less accurate than code-gen toolchains.
25
23
26
- private static readonly TimeInterval FallbackCpuResolutionValue = TimeInterval . FromNanoseconds ( 0.2d ) ;
27
-
28
24
public ExpectedBenchmarkResultsTests ( ITestOutputHelper output ) : base ( output ) { }
29
25
30
26
private static IEnumerable < Type > EmptyBenchmarkTypes ( ) =>
@@ -109,9 +105,6 @@ private void AssertZeroResults(Type benchmarkType, IConfig config)
109
105
. AddDiagnoser ( new MemoryDiagnoser ( new MemoryDiagnoserConfig ( false ) ) )
110
106
) ;
111
107
112
- var cpuResolution = RuntimeInformation . GetCpuInfo ( ) . MaxFrequency ? . ToResolution ( ) ?? FallbackCpuResolutionValue ;
113
- var cpuGhz = cpuResolution . ToFrequency ( ) . ToGHz ( ) ;
114
-
115
108
foreach ( var report in summary . Reports )
116
109
{
117
110
var workloadMeasurements = report . AllMeasurements . Where ( m => m . Is ( IterationMode . Workload , IterationStage . Actual ) ) . GetStatistics ( ) . WithoutOutliers ( ) ;
@@ -120,11 +113,8 @@ private void AssertZeroResults(Type benchmarkType, IConfig config)
120
113
bool isZero = ZeroMeasurementHelper . CheckZeroMeasurementTwoSamples ( workloadMeasurements , overheadMeasurements ) ;
121
114
Assert . True ( isZero , $ "Actual time was not 0.") ;
122
115
123
- var workloadTime = workloadMeasurements . Average ( ) ;
124
- var overheadTime = overheadMeasurements . Average ( ) ;
125
-
126
- // Allow for 1 cpu cycle variance
127
- Assert . True ( overheadTime * cpuGhz < workloadTime * cpuGhz + 1 , "Overhead took more time than workload." ) ;
116
+ isZero = ZeroMeasurementHelper . CheckZeroMeasurementTwoSamples ( overheadMeasurements , workloadMeasurements ) ;
117
+ Assert . True ( isZero , "Overhead took more time than workload." ) ;
128
118
129
119
Assert . True ( ( report . GcStats . GetBytesAllocatedPerOperation ( report . BenchmarkCase ) ?? 0L ) == 0L , "Memory allocations measured above 0." ) ;
130
120
}
@@ -168,9 +158,6 @@ private void AssertDifferentSizedStructsResults(IConfig config)
168
158
. AddDiagnoser ( new MemoryDiagnoser ( new MemoryDiagnoserConfig ( false ) ) )
169
159
) ;
170
160
171
- var cpuResolution = RuntimeInformation . GetCpuInfo ( ) . MaxFrequency ? . ToResolution ( ) ?? FallbackCpuResolutionValue ;
172
- var cpuGhz = cpuResolution . ToFrequency ( ) . ToGHz ( ) ;
173
-
174
161
foreach ( var report in summary . Reports )
175
162
{
176
163
var workloadMeasurements = report . AllMeasurements . Where ( m => m . Is ( IterationMode . Workload , IterationStage . Actual ) ) . GetStatistics ( ) . WithoutOutliers ( ) ;
@@ -179,11 +166,8 @@ private void AssertDifferentSizedStructsResults(IConfig config)
179
166
bool isZero = ZeroMeasurementHelper . CheckZeroMeasurementTwoSamples ( workloadMeasurements , overheadMeasurements ) ;
180
167
Assert . False ( isZero , $ "Actual time was 0.") ;
181
168
182
- var workloadTime = workloadMeasurements . Average ( ) ;
183
- var overheadTime = overheadMeasurements . Average ( ) ;
184
-
185
- // Allow for 1 cpu cycle variance
186
- Assert . True ( overheadTime * cpuGhz < workloadTime * cpuGhz + 1 , "Overhead took more time than workload." ) ;
169
+ isZero = ZeroMeasurementHelper . CheckZeroMeasurementTwoSamples ( overheadMeasurements , workloadMeasurements ) ;
170
+ Assert . True ( isZero , "Overhead took more time than workload." ) ;
187
171
188
172
Assert . True ( ( report . GcStats . GetBytesAllocatedPerOperation ( report . BenchmarkCase ) ?? 0L ) == 0L , "Memory allocations measured above 0." ) ;
189
173
}
0 commit comments