Skip to content

testing: support underscore separators in -benchtime counts #60176

@mvdan

Description

@mvdan

What version of Go are you using (go version)?

$ go version
go version devel go1.21-91b8cc0dfa Sat May 13 00:22:50 2023 +0000 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/mvdan/.cache/go-build'
GOENV='/home/mvdan/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/mvdan/go/pkg/mod'
GONOPROXY='github.com/cue-unity'
GONOSUMDB='github.com/cue-unity'
GOOS='linux'
GOPATH='/home/mvdan/go'
GOPRIVATE='github.com/cue-unity'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/mvdan/tip'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLDIR='/home/mvdan/tip/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='devel go1.21-91b8cc0dfa Sat May 13 00:22:50 2023 +0000'
GCCGO='gccgo'
GOAMD64='v3'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1112140393=/tmp/go-build -gno-record-gcc-switches'
GOROOT/bin/go version: go version devel go1.21-91b8cc0dfa Sat May 13 00:22:50 2023 +0000 linux/amd64
GOROOT/bin/go tool compile -V: compile version devel go1.21-91b8cc0dfa Sat May 13 00:22:50 2023 +0000
uname -sr: Linux 6.3.1-arch2-1
LSB Version:	n/a
Distributor ID:	Arch
Description:	Arch Linux
Release:	rolling
Codename:	n/a
/usr/lib/libc.so.6: GNU C Library (GNU libc) stable release version 2.37.
gdb --version: GNU gdb (GDB) 13.1

What did you do?

go test -bench=. -benchtime=40_000x, because I found that easier to read than -benchtime=40000x .

What did you expect to see?

It should work the same with or without underscores, like numeric literals in Go code.

What did you see instead?

invalid value "40_000x" for flag -test.benchtime: invalid count

This appears to be because we call strconv.ParseInt with base = 10, and the API is documented to only support underscore separators with base = 0. Slightly unfortunate if we don't want to support other bases like -benchtime=0x123, but I guess they're not harmful either.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions