Skip to content

Instantly share code, notes, and snippets.

View ifraixedes's full-sized avatar
🌍

Ivan Fraixedes ifraixedes

🌍
View GitHub Profile
@ifraixedes
ifraixedes / blog_ifaixedes_sync_pool_test.go
Created October 15, 2025 17:35
The Go test file that used to benchmark allocations of sync.Pool and I wrote a post about https://blog.fraixed.es/post/move-to-heap-golang-std-pool
// This was a benchmark that I used to understand how to use sync.Pool without allocations.
// Pointers key as stated in the documentation, but how you use them is also important.
// I wrote about it in https://blog.fraixed.es/post/move-to-heap-golang-std-pool
// To execute the benchmarks use `go test -bench . -benchmem`. The only interesting part is the last
// column, the `allocs/op`; when the benchmark function shows 0 is good, otherwise is bad.
package tmp
import (
"sync"