Created
May 17, 2014 21:53
-
-
Save collinvandyck/4f049abef8b3cddf28fc 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 "testing" | |
| type Foo struct { | |
| } | |
| func (f *Foo) Hi() { | |
| } | |
| type IFoo interface { | |
| Hi() | |
| } | |
| // BenchmarkInterface 1000000000 2.12 ns/op | |
| func BenchmarkInterface(b *testing.B) { | |
| var f IFoo = &Foo{} | |
| for i := 0; i < b.N; i++ { | |
| f.Hi() | |
| } | |
| } | |
| // BenchmarkStruct 2000000000 0.31 ns/op | |
| func BenchmarkStruct(b *testing.B) { | |
| f := &Foo{} | |
| for i := 0; i < b.N; i++ { | |
| f.Hi() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment