Skip to content

Instantly share code, notes, and snippets.

@james4k
Created October 24, 2012 02:39
Show Gist options
  • Save james4k/3943394 to your computer and use it in GitHub Desktop.
Save james4k/3943394 to your computer and use it in GitHub Desktop.
package main
// void nothing() {}
import "C"
import "fmt"
import "testing"
func nothing() {}
func CNothing(b *testing.B) {
for i := 0; i < b.N; i++ {
C.nothing()
}
}
func GoNothing(b *testing.B) {
for i := 0; i < b.N; i++ {
nothing()
}
}
func main() {
result := testing.Benchmark(CNothing)
fmt.Println(result)
result = testing.Benchmark(GoNothing)
fmt.Println(result)
}
MacJames:bench jamesgray$ go build -gcflags=-N
MacJames:bench jamesgray$ ./bench
20000000 82.7 ns/op
2000000000 1.70 ns/op
MacJames:bench jamesgray$ ./bench
20000000 82.9 ns/op
2000000000 1.70 ns/op
MacJames:bench jamesgray$ go build -gcflags=
MacJames:bench jamesgray$ ./bench
20000000 86.9 ns/op
2000000000 0.42 ns/op
MacJames:bench jamesgray$ ./bench
20000000 84.4 ns/op
2000000000 0.43 ns/op
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment