Created
October 24, 2020 17:29
-
-
Save 0xc0d/83b48981c647efbffb16b5c4b650f1cd to your computer and use it in GitHub Desktop.
Benchmark: sync.Pool vs simple allocation
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
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