Skip to content

Instantly share code, notes, and snippets.

@0xc0d
Created October 24, 2020 17:29
Show Gist options
  • Save 0xc0d/83b48981c647efbffb16b5c4b650f1cd to your computer and use it in GitHub Desktop.
Save 0xc0d/83b48981c647efbffb16b5c4b650f1cd to your computer and use it in GitHub Desktop.
Benchmark: sync.Pool vs simple allocation
func BenchmarkPool(b *testing.B) {
var p sync.Pool
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
p.Put(1)
p.Get()
}
})
}
func BenchmarkAllocation(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
i := 0
i = i
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment