Skip to content

Instantly share code, notes, and snippets.

@pjebs
Created June 25, 2020 02:23
Show Gist options
  • Save pjebs/5c3f81f6001aff1b4dd3d7b5e451839a to your computer and use it in GitHub Desktop.
Save pjebs/5c3f81f6001aff1b4dd3d7b5e451839a to your computer and use it in GitHub Desktop.
go benchmark structure
func Benchmark(b *testing.B) {
setup()
defer cleanup()
limits := []int{
5,
50,
500,
10000,
}
for _, lim := range limits { // Fetch varying number of rows
lim := lim
// Benchmark dbq
b.Run(fmt.Sprintf("dbq limit:%d", lim), func(b *testing.B) {
for i := 0; i < b.N; i++ {
}
})
// Benchmark sqlx
b.Run(fmt.Sprintf("sqlx limit:%d", lim), func(b *testing.B) {
for i := 0; i < b.N; i++ {
}
})
// Benchmark gorm
b.Run(fmt.Sprintf("gorm limit:%d", lim), func(b *testing.B) {
for i := 0; i < b.N; i++ {
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment