-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed as duplicate of#43179
Closed as duplicate of#43179
Copy link
Labels
ToolProposalIssues describing a requested change to a Go tool or command-line program.Issues describing a requested change to a Go tool or command-line program.
Description
Go version
go version go1.24.2 windows/amd64
Output of go env
in your module/workspace:
set AR=ar
set CC=gcc
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_ENABLED=0
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set CXX=g++
set GCCGO=gccgo
set GO111MODULE=
set GOAMD64=v1
set GOARCH=amd64
set GOAUTH=netrc
set GOBIN=
set GOCACHE=C:\Users\u1\AppData\Local\go-build
set GOCACHEPROG=
set GODEBUG=
set GOENV=C:\Users\u1\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFIPS140=off
set GOFLAGS=
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\USER_N~1\AppData\Local\Temp\go-build3576284606=/tmp/go-build -gno-record-gcc-switches
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMOD=E:\go\ch1\echo_test\go.mod
set GOMODCACHE=C:\Users\u1\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\u1\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTELEMETRY=local
set GOTELEMETRYDIR=C:\Users\u1\AppData\Roaming\go\telemetry
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.24.2
set GOWORK=
set PKG_CONFIG=pkg-config
What did you do?
Tried to run "go test" benchmark tool.
Here's the code:
package echo_test
import (
"strings"
"testing"
)
var (
args_slice = []string{"a0", "a1", "a2", "a3", "a4"}
sep string = ""
s string = ""
)
func BenchmarkEchoStandardLoop(b *testing.B) {
s = ""
sep = ""
for i := 0; i < b.N; i++ {
for j := 0; j < len(args_slice); j++ {
s += sep + args_slice[j]
sep = " "
}
}
}
func BenchmarkEchoRangeLoop(b *testing.B) {
s = ""
sep = ""
for i := 0; i < b.N; i++ {
for _, arg := range args_slice {
s += sep + arg
sep = " "
}
}
}
func BenchmarkEchoStringsJoin(b *testing.B) {
s = ""
sep = ""
for i := 0; i < b.N; i++ {
s = strings.Join(args_slice, " ")
}
}
What did you see happen?
With "go test -bench=." it printed:
ok echo_test 0.291s [no tests to run]
But with "go test -bench ." it launched the benchmark:
...
BenchmarkEchoStandardLoop-8 16408 109289 ns/op
BenchmarkEchoRangeLoop-8 17733 127269 ns/op
BenchmarkEchoStringsJoin-8 13529373 85.89 ns/op
What did you expect to see?
Expected to see the result of the benchmark.
Metadata
Metadata
Assignees
Labels
ToolProposalIssues describing a requested change to a Go tool or command-line program.Issues describing a requested change to a Go tool or command-line program.