diff --git a/bench_test.go b/bench_test.go index dbee1c0..903b5f2 100644 --- a/bench_test.go +++ b/bench_test.go @@ -23,8 +23,11 @@ func yesErrors(at, depth int) error { return yesErrors(at+1, depth) } +// GlobalE is an exported global to store the result of benchmark results, +// preventing the compiler from optimising the benchmark functions away. +var GlobalE error + func BenchmarkErrors(b *testing.B) { - var toperr error type run struct { stack int std bool @@ -54,7 +57,7 @@ func BenchmarkErrors(b *testing.B) { err = f(0, r.stack) } b.StopTimer() - toperr = err + GlobalE = err }) } }