mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-24 17:28:31 +02:00
tweak: optimize memory usage and allocation
This commit is contained in:
43
internal/utils/synk/pool_bench_test.go
Normal file
43
internal/utils/synk/pool_bench_test.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package synk
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
var sizes = []int{1024, 4096, 16384, 65536, 32 * 1024, 128 * 1024, 512 * 1024, 1024 * 1024}
|
||||
|
||||
func BenchmarkBytesPool_GetSmall(b *testing.B) {
|
||||
for b.Loop() {
|
||||
bytesPool.Put(bytesPool.GetSized(1024))
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkBytesPool_MakeSmall(b *testing.B) {
|
||||
for b.Loop() {
|
||||
_ = make([]byte, 1024)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkBytesPool_GetLarge(b *testing.B) {
|
||||
for b.Loop() {
|
||||
bytesPool.Put(bytesPool.GetSized(1024 * 1024))
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkBytesPool_MakeLarge(b *testing.B) {
|
||||
for b.Loop() {
|
||||
_ = make([]byte, 1024*1024)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkBytesPool_GetAll(b *testing.B) {
|
||||
for i := range b.N {
|
||||
bytesPool.Put(bytesPool.GetSized(sizes[i%len(sizes)]))
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkBytesPool_MakeAll(b *testing.B) {
|
||||
for i := range b.N {
|
||||
_ = make([]byte, sizes[i%len(sizes)])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user