diff --git a/pool/pool.go b/pool/pool.go index b80a99f..10b0c34 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -1,5 +1,10 @@ package pool +type Pool[T any] interface { + Get() (o T) + Put(o T) +} + type pool[T any] struct { noCopy struct{} c chan T diff --git a/pool/pool_test.go b/pool/pool_test.go index bcaf577..12b8a63 100644 --- a/pool/pool_test.go +++ b/pool/pool_test.go @@ -52,3 +52,15 @@ func BenchmarkPool(b *testing.B) { } }) } + +func BenchmarkPoolNew(b *testing.B) { + p := pool.NewPoolWithNew(100, func() int { + return 100 + }) + + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + p.Put(p.Get()) + } + }) +}