Skip to content
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, impossibly low ns/op #69417

Closed
cblach opened this issue Sep 12, 2024 · 2 comments
Closed

testing: Benchmark, impossibly low ns/op #69417

cblach opened this issue Sep 12, 2024 · 2 comments

Comments

@cblach
Copy link

cblach commented Sep 12, 2024

Go version

go version go1.23.1 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/christian.blach/Library/Caches/go-build'
GOENV='/Users/christian.blach/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/christian.blach/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/christian.blach/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.23.1/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.23.1/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.23.1'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/christian.blach/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/christian.blach/repos/exp/benchmarkbug/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/h9/th1sbhm15pjfb3vx7h5kr46c0000gq/T/go-build1899405527=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

I created a simple benchmark file and I get ns/op in the femtosecond range.

package main

import (
	"math/rand/v2"
	"testing"
)

func BenchmarkRandInt(b *testing.B) {
	rand.Int()
}

What did you see happen?

$ go test -bench='.' -count=1
goos: darwin
goarch: arm64
pkg: benchmarkbug
cpu: Apple M3 Pro
BenchmarkRandInt-11 1000000000 0.0000003 ns/op
PASS
ok benchmarkbug 0.210s

What did you expect to see?

I expected not to see operations completed in sub femtosecond time.

Possible cause: It seems that go test believes that it ran 1000000000 tests while it only ran one and then probably divided the run time with 1000000000.

@cblach
Copy link
Author

cblach commented Sep 12, 2024

My error: I saw the issue and realized my mistake

#40012

@cblach cblach closed this as completed Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants