Skip to content

Instantly share code, notes, and snippets.

@collinvandyck
Created May 17, 2014 21:53
Show Gist options
  • Select an option

  • Save collinvandyck/4f049abef8b3cddf28fc to your computer and use it in GitHub Desktop.

Select an option

Save collinvandyck/4f049abef8b3cddf28fc to your computer and use it in GitHub Desktop.
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