Skip to content

Commit 718031a

Browse files
authored
hardware counters: don't try to exclude non-existing overhead for long running benchmarks (#1547)
1 parent 349e900 commit 718031a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/BenchmarkDotNet.Diagnostics.Windows/Tracing/TraceLogParser.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,15 @@ public IEnumerable<Metric> CalculateMetrics(Dictionary<int, int> profileSourceId
144144

145145
overheadTotalPerCounter.TryGetValue(perCounter.Key, out var overhead);
146146

147-
double result = (perCounter.Value / (double) workloadIterations.Length - overhead / (double) overheadIterations.Length)
148-
/ totalOperationsPerIteration.Value; // result = (avg(workload) - avg(overhead))/op
147+
// result = (avg(workload) - avg(overhead))/op
148+
double result = perCounter.Value / (double)workloadIterations.Length;
149+
150+
if (overheadIterations.Length > 0) // we skip the overhead phase for long-running benchmarks
151+
{
152+
result -= (overhead / (double)overheadIterations.Length);
153+
}
154+
155+
result /= totalOperationsPerIteration.Value;
149156

150157
return new Metric(new PmcMetricDescriptor(pmc), result);
151158
});

0 commit comments

Comments
 (0)