Skip to content

Commit 5b2ce02

Browse files
authored
Stabilize benchmark result of BenchmarkValueEqual (#5717)
`BenchmarkValueEqual` does not run the target code with `b.N`, as https://pkg.go.dev/testing#hdr-Benchmarks states. Thus, it cannot produce a stable benchmark result. And, it would fail the benchmark: https://github.com/open-telemetry/opentelemetry-go/actions/runs/10412186663. This PR fixes this issue. Here is the result of `benchstat` ``` goos: darwin goarch: arm64 pkg: go.opentelemetry.io/otel/log │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ ValueEqual/2_with_1-10 0.0000002000n ± 100% 3.1450000000n ± 1% +1572499900.00% (p=0.000 n=10) │ old.txt │ new.txt │ │ B/op │ B/op vs base │ ValueEqual/2_with_1-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ ¹ all samples are equal │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ ValueEqual/2_with_1-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ ¹ all samples are equal ```
1 parent d61bbf1 commit 5b2ce02

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

log/keyvalue_bench_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,9 @@ func BenchmarkValueEqual(b *testing.B) {
225225
for _, v2 := range vals {
226226
b.Run(v1.String()+" with "+v2.String(), func(b *testing.B) {
227227
b.ReportAllocs()
228-
_ = v1.Equal(v2)
228+
for i := 0; i < b.N; i++ {
229+
_ = v1.Equal(v2)
230+
}
229231
})
230232
}
231233
}

0 commit comments

Comments
 (0)