From 5bf83cc153cc75d53a66b7560e73d6a61bbbb6ea Mon Sep 17 00:00:00 2001 From: charlie <3140647@qq.com> Date: Fri, 6 May 2022 15:30:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pool/pool.go | 5 +++++ pool/pool_test.go | 12 ++++++++++++ 2 files changed, 17 insertions(+) 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()) + } + }) +}