Created
November 27, 2013 15:55
-
-
Save codegangsta/7678025 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ( | |
"github.com/codegangsta/inject" | |
"reflect" | |
"testing" | |
) | |
func helloWorld(val string) { | |
i := 0 | |
i++ | |
} | |
func BenchmarkFunctionCall(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
helloWorld("foo") | |
} | |
} | |
func BenchmarkReflectCall(b *testing.B) { | |
val := reflect.ValueOf(helloWorld) | |
for i := 0; i < b.N; i++ { | |
val.Call([]reflect.Value{reflect.ValueOf("foo")}) | |
} | |
} | |
func BenchmarkInvoke(b *testing.B) { | |
injector := inject.New() | |
injector.Map("foo") | |
for i := 0; i < b.N; i++ { | |
injector.Invoke(helloWorld) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
BenchmarkFunctionCall 2000000000 0.57 ns/op
BenchmarkReflectCall 5000000 380 ns/op
BenchmarkInvoke 5000000 538 ns/op