mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 00:22:41 +08:00
添加接口
This commit is contained in:
@ -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
|
||||||
|
@ -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())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user