Skip to content

Commit 7f163c8

Browse files
committed
Use ZeroMeasurementHelper for both checks.
1 parent 78ce31d commit 7f163c8

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

tests/BenchmarkDotNet.IntegrationTests.ManualRunning/ExpectedBenchmarkResultsTests.cs

+4-20
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
using BenchmarkDotNet.Engines;
99
using BenchmarkDotNet.Extensions;
1010
using BenchmarkDotNet.Jobs;
11-
using BenchmarkDotNet.Portability;
1211
using BenchmarkDotNet.Reports;
1312
using BenchmarkDotNet.Tests.XUnit;
1413
using BenchmarkDotNet.Toolchains.InProcess.Emit;
15-
using Perfolizer.Horology;
1614
using Xunit;
1715
using Xunit.Abstractions;
1816

@@ -23,8 +21,6 @@ public class ExpectedBenchmarkResultsTests : BenchmarkTestExecutor
2321
// NativeAot takes a long time to build, so not including it in these tests.
2422
// We also don't test InProcessNoEmitToolchain because it is known to be less accurate than code-gen toolchains.
2523

26-
private static readonly TimeInterval FallbackCpuResolutionValue = TimeInterval.FromNanoseconds(0.2d);
27-
2824
public ExpectedBenchmarkResultsTests(ITestOutputHelper output) : base(output) { }
2925

3026
private static IEnumerable<Type> EmptyBenchmarkTypes() =>
@@ -109,9 +105,6 @@ private void AssertZeroResults(Type benchmarkType, IConfig config)
109105
.AddDiagnoser(new MemoryDiagnoser(new MemoryDiagnoserConfig(false)))
110106
);
111107

112-
var cpuResolution = RuntimeInformation.GetCpuInfo().MaxFrequency?.ToResolution() ?? FallbackCpuResolutionValue;
113-
var cpuGhz = cpuResolution.ToFrequency().ToGHz();
114-
115108
foreach (var report in summary.Reports)
116109
{
117110
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)
120113
bool isZero = ZeroMeasurementHelper.CheckZeroMeasurementTwoSamples(workloadMeasurements, overheadMeasurements);
121114
Assert.True(isZero, $"Actual time was not 0.");
122115

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.");
128118

129119
Assert.True((report.GcStats.GetBytesAllocatedPerOperation(report.BenchmarkCase) ?? 0L) == 0L, "Memory allocations measured above 0.");
130120
}
@@ -168,9 +158,6 @@ private void AssertDifferentSizedStructsResults(IConfig config)
168158
.AddDiagnoser(new MemoryDiagnoser(new MemoryDiagnoserConfig(false)))
169159
);
170160

171-
var cpuResolution = RuntimeInformation.GetCpuInfo().MaxFrequency?.ToResolution() ?? FallbackCpuResolutionValue;
172-
var cpuGhz = cpuResolution.ToFrequency().ToGHz();
173-
174161
foreach (var report in summary.Reports)
175162
{
176163
var workloadMeasurements = report.AllMeasurements.Where(m => m.Is(IterationMode.Workload, IterationStage.Actual)).GetStatistics().WithoutOutliers();
@@ -179,11 +166,8 @@ private void AssertDifferentSizedStructsResults(IConfig config)
179166
bool isZero = ZeroMeasurementHelper.CheckZeroMeasurementTwoSamples(workloadMeasurements, overheadMeasurements);
180167
Assert.False(isZero, $"Actual time was 0.");
181168

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.");
187171

188172
Assert.True((report.GcStats.GetBytesAllocatedPerOperation(report.BenchmarkCase) ?? 0L) == 0L, "Memory allocations measured above 0.");
189173
}

0 commit comments

Comments
 (0)