go test -bench=. -benchmem
goos: darwin
goarch: amd64
pkg: fmt-perf
BenchmarkFmtV-16 6899274 174 ns/op 64 B/op 1 allocs/op
BenchmarkFmtS-16 9181304 129 ns/op 80 B/op 2 allocs/op
PASS
ok fmt-perf 4.138s
Last active
February 18, 2020 19:12
-
-
Save embano1/44d7d66ace1dec171f17f44fd3af2b4d to your computer and use it in GitHub Desktop.
Benchmark fmt.Sprintf %v vs %s
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fmtperf | |
import ( | |
"errors" | |
"fmt" | |
"testing" | |
) | |
var ( | |
err = errors.New("failed to connect to sidecar server") | |
output string | |
) | |
func BenchmarkFmtV(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
msg := fmt.Sprintf("could not get root node: %v", err) | |
output = msg | |
} | |
} | |
func BenchmarkFmtS(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
msg := fmt.Sprintf("could not get root node: %s", err.Error()) | |
output = msg | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment