-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
testing: Benchmark doesn't collect result of sub-benchmarks #18815
Comments
I think the bug is that |
There may be a but as @ianlancetaylor says, but I would still not expect the testing package to work properly unless the program is run with go test. The go test command sets up the environment for the test and benchmarks. The go run command does not. |
b.run1() seems to return true. Sub - benchmark is evaluated N times, no once, checked with debug prints. RunParallel() works as expected in same circumstances. |
@robpike I always thought this was an intended and documented use case for the testing package. Otherwise, what is the purpose of the Benchmark function?
|
The purpose of the Benchmark function is to run a benchmark under the auspices of "go test". Here is the start of the package docs:
|
I agree this is a bug. Like Ian said, it should still return b.result. |
CL https://golang.org/cl/36990 mentions this issue. |
CL https://golang.org/cl/37530 mentions this issue. |
The run1 call removed in golang.org/cl/36990 was necessary to initialize the duration of the benchmark. With it gone, the math in launch() starts from 100. This doesn't work out well for second-long benchmark methods. Put it back. Updates #18815 Change-Id: I461f3466c805d0c61124a2974662f7ad45335794 Reviewed-on: https://go-review.googlesource.com/37530 Run-TryBot: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?1.7.4
go version devel +78860b2ad
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build805050938=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
What did you do?
I run program normal way, not "go test". I call testing.Benchmark() in code. Benchmark function call Run() method to execute sub benchmark.
Behaviour already reproduced prooflink http://stackoverflow.com/questions/41861918/using-testing-benchmark-does-not-produce-any-output
What did you expect to see?
According to the documentation I expect
What did you see instead?
Sub benchmark run N times(no once) but result is
0 0 ns/op
The text was updated successfully, but these errors were encountered: