123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package bufpool
- import (
- "math/rand"
- "sync"
- "testing"
- "github.com/imgproxy/imgproxy/v3/config"
- )
- var (
- testData [][]byte
- testDataOnce sync.Once
- testMu sync.Mutex
- )
- func initTestData() {
- testData = make([][]byte, 1000)
- for i := 6; i < 1000; i++ {
- testData[i] = make([]byte, i*1271)
- }
- rand.Shuffle(len(testData), func(i, j int) { testData[i], testData[j] = testData[j], testData[i] })
- }
- func BenchmarkBufpool(b *testing.B) {
- testMu.Lock()
- defer testMu.Unlock()
- config.Reset()
- testDataOnce.Do(initTestData)
- pool := New("test", 16, 0)
- b.ResetTimer()
- b.SetParallelism(16)
- b.RunParallel(func(pb *testing.PB) {
- for pb.Next() {
- for _, bb := range testData {
- buf := pool.Get(len(bb), false)
- buf.Write(bb)
- pool.Put(buf)
- }
- }
- })
- }
|