Open empijei opened 5 years ago
Are calls to testing.Benchmark
within a benchmark supported? But I agree that something is wrong. Even if they're not supported, the testing package should error properly instead of deadlocking.
Current doc states
Benchmark benchmarks a single function. Useful for creating custom benchmarks that do not use the "go test" command.
Should this be corrected to something that specifies it should only be used for those cases that do not use "go test" or it is clear enough and I just misread it?
What is the proper way to compare speeds of functions as a part of go test?
If I want to average a bunch of separate benchmarks together for example of different file sizes what would be the proper way to do it?
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Called testing.Benchmark in a Benchmark. The reason for this is that I wanted to check during benchmarks which one of two possible implementations would be faster on the current machine and for a set of given inputs.
Here is a minimal repro that should be run as a benchmark to crash (must be in *_test.go and should be run with
go test -bench=.
)What did you expect to see?
"Difference between executions is ~1ns
What did you see instead?
Probable cause
During the first iteration of
benchFunc
run1
is executed.run1
invokesrunN
which will runrun1
. The issue is thatrunN
tries to acquire a global lock while holding it, causing the deadlock.Source for
runN
:Source for
run1
: