Closed
Description
go version go1.11 linux/amd64
go version devel +43530e6b25 Fri Oct 26 12:37:30 2018 +0000 linux/amd64
Playground: https://play.golang.org/p/34va1HU2FJ7.
Results:
$ go test -bench . benchlen_test.go
goos: linux
goarch: amd64
BenchmarkLen/const-4 2000000000 0.55 ns/op
BenchmarkLen/const_local-4 2000000000 0.54 ns/op
BenchmarkLen/var-4 2000000000 0.58 ns/op
BenchmarkLen/var_local-4 2000000000 0.41 ns/op
PASS
ok command-line-arguments 4.374s
len(local string variable)
is consistently 15-20% faster on my machine. While global vs local []byte
have the same performance.