Created
October 24, 2012 02:39
-
-
Save james4k/3943394 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 | |
// 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) | |
} |
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
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