Skip to content

Instantly share code, notes, and snippets.

@zaquestion
Created February 21, 2018 23:13
Show Gist options
  • Save zaquestion/54fa7a1724a7c539151a36a61fba4fcd to your computer and use it in GitHub Desktop.
Save zaquestion/54fa7a1724a7c539151a36a61fba4fcd to your computer and use it in GitHub Desktop.
package main
import (
"testing"
)
const (
foo = "bar"
)
var escape interface{}
func BenchmarkConstantDefined(b *testing.B) {
for i := 0; i < b.N; i++ {
escape = hello(foo)
}
}
func BenchmarkConstantLiteral(b *testing.B) {
for i := 0; i < b.N; i++ {
escape = hello("bar")
}
}
func BenchmarkVar(b *testing.B) {
for i := 0; i < b.N; i++ {
foo := "bar"
escape = hello(foo)
}
}
func hello(s string) string {
return "world, " + s
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment