1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 00:22:41 +08:00

添加接口

This commit is contained in:
2022-05-06 15:30:58 +08:00
parent d0e055016b
commit 5bf83cc153
2 changed files with 17 additions and 0 deletions

View File

@ -1,5 +1,10 @@
package pool package pool
type Pool[T any] interface {
Get() (o T)
Put(o T)
}
type pool[T any] struct { type pool[T any] struct {
noCopy struct{} noCopy struct{}
c chan T c chan T

View File

@ -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())
}
})
}