feat(pool): introduce BytesPoolWithMemory for optimized memory management and add benchmark for memory usage

This commit is contained in:
yusing
2025-08-30 11:19:05 +08:00
parent 04657420b8
commit 31d49453a7
2 changed files with 85 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
package synk
import (
"slices"
"testing"
)
@@ -36,6 +37,13 @@ func BenchmarkBytesPool_GetAll(b *testing.B) {
}
}
func BenchmarkBytesPoolWithMemory(b *testing.B) {
pool := GetBytesPoolWithUniqueMemory()
for i := range b.N {
pool.Put(slices.Grow(pool.Get(), sizes[i%len(sizes)]))
}
}
func BenchmarkBytesPool_MakeAll(b *testing.B) {
for i := range b.N {
_ = make([]byte, sizes[i%len(sizes)])