Closed as duplicate of#73137
Closed as duplicate of#73137
Description
Go version
go version devel go1.25-5eaeb7b455 Thu Apr 3 15:36:36 2025 -0700 linux/amd64
Output of go env
in your module/workspace:
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE='on'
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/user/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/user/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1699666494=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/tmp/bench-loop-rangefunc/go.mod'
GOMODCACHE='/home/user/golang/pkg/mod'
GOOS='linux'
GOPATH='/home/user/golang'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org'
GOROOT='/home/user/go-dev'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/home/user/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/home/user/go-dev/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='devel go1.25-5eaeb7b455 Thu Apr 3 15:36:36 2025 -0700'
GOWORK=''
PKG_CONFIG='pkg-config'
What did you do?
Convert an old style benchmark loop containing a range-func loop to the new B.Loop
construct.
Example benchmark: https://go.dev/play/p/TMQqkLTVnxB
What did you see happen?
goos: linux
goarch: amd64
pkg: bench
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
BenchmarkIterRangeFunc-8 307616280 3.897 ns/op
BenchmarkLoopRangeFunc-8 13051561 96.68 ns/op
PASS
ok bench 2.861s
What did you expect to see?
The timing result should be roughly similar for both benchmarks, but instead there is a fairly severe performance reduction with B.Loop
(25x).
This appears to be a good example of something to fix so B.Loop
is more reliable and useful as per #73137 (comment).