Skip to content

Instantly share code, notes, and snippets.

@kylelemons
Created June 6, 2011 15:43
Show Gist options
  • Save kylelemons/1010494 to your computer and use it in GitHub Desktop.
Save kylelemons/1010494 to your computer and use it in GitHub Desktop.
Benchmark function calls
package main
import (
"fmt"
"testing"
)
func readonly() {}
var readwrite = func() {}
func main() {
fmt.Printf("readonly: %s\n", testing.Benchmark(func(b *testing.B) {
for i := 0; i < b.N; i++ {
readonly()
}
}))
fmt.Printf("readwrite: %s\n", testing.Benchmark(func(b *testing.B) {
for i := 0; i < b.N; i++ {
readwrite()
}
}))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment