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