Skip to content

Instantly share code, notes, and snippets.

@ash2k
Created May 21, 2016 10:52
Show Gist options
  • Save ash2k/a4040ebe9616ff1d22e5bc01d16a2bac to your computer and use it in GitHub Desktop.
Save ash2k/a4040ebe9616ff1d22e5bc01d16a2bac to your computer and use it in GitHub Desktop.
var sink string
var x string = "somestring"
// BenchmarkPrint-8 10000000 198 ns/op 32 B/op 2 allocs/op
func BenchmarkPrint(b *testing.B) {
b.ReportAllocs()
var s string
for i := 0; i < b.N; i++ {
s = fmt.Sprintf("abc.%s", x)
}
sink = s
}
// BenchmarkConcat-8 20000000 62.6 ns/op 16 B/op 1 allocs/op
func BenchmarkConcat(b *testing.B) {
b.ReportAllocs()
var s string
for i := 0; i < b.N; i++ {
s = "abc." + x
}
sink = s
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment