Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,15 @@ var NewNilCheck = newNilCheck
func NewRequestPool[T any](v T) pool[T] {
return newRequestPool(v)
}

func NewRequestDecoder[T any](v T) requestDecoder[T] { //nolint:revive
return newRequestDecoder(v)
}

func PoolNew[T any](p pool[T]) any {
return p.(*requestPool[T]).pool.New()
}

func PoolReset[T any](p pool[T], x *T) {
p.(*requestPool[T]).reset(x)
}
59 changes: 59 additions & 0 deletions pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,62 @@ func TestRequestPool(t *testing.T) {
}
})
}

func BenchmarkPool(b *testing.B) {
type item struct {
String string
Pointer *string
}
b.Run("Struct", func(b *testing.B) {
pool := don.NewRequestPool(item{})
for i := 0; i < b.N; i++ {
pool.Put(pool.Get())
}
})
b.Run("Pointer", func(b *testing.B) {
pool := don.NewRequestPool(new(item))
for i := 0; i < b.N; i++ {
pool.Put(pool.Get())
}
})
}

func BenchmarkPool_New(b *testing.B) {
type item struct {
String string
Pointer *string
}
b.Run("Struct", func(b *testing.B) {
pool := don.NewRequestPool(item{})
for i := 0; i < b.N; i++ {
don.PoolNew(pool)
}
})
b.Run("Pointer", func(b *testing.B) {
pool := don.NewRequestPool(new(item))
for i := 0; i < b.N; i++ {
don.PoolNew(pool)
}
})
}

func BenchmarkPool_Reset(b *testing.B) {
type item struct {
String string
Pointer *string
}
b.Run("Struct", func(b *testing.B) {
pool := don.NewRequestPool(item{})
x := item{}
for i := 0; i < b.N; i++ {
don.PoolReset(pool, &x)
}
})
b.Run("Pointer", func(b *testing.B) {
pool := don.NewRequestPool(new(item))
x := new(item)
for i := 0; i < b.N; i++ {
don.PoolReset(pool, &x)
}
})
}