Created
February 21, 2018 23:13
-
-
Save zaquestion/54fa7a1724a7c539151a36a61fba4fcd to your computer and use it in GitHub Desktop.
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 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