(b *testing.B)
| 93 | } |
| 94 | |
| 95 | func BenchmarkWaitPoolEmpty(b *testing.B) { |
| 96 | var wg sync.WaitGroup |
| 97 | var trials atomic.Int32 |
| 98 | trials.Store(int32(b.N)) |
| 99 | workers := runtime.NumCPU() + 2 |
| 100 | if workers-4 <= 0 { |
| 101 | b.Skip("Not enough cores") |
| 102 | } |
| 103 | p := NewWaitPool(0, func() any { return make([]byte, 16) }) |
| 104 | wg.Add(workers) |
| 105 | b.ResetTimer() |
| 106 | for i := 0; i < workers; i++ { |
| 107 | go func() { |
| 108 | defer wg.Done() |
| 109 | for trials.Add(-1) > 0 { |
| 110 | x := p.Get() |
| 111 | time.Sleep(time.Duration(rand.Intn(100)) * time.Microsecond) |
| 112 | p.Put(x) |
| 113 | } |
| 114 | }() |
| 115 | } |
| 116 | wg.Wait() |
| 117 | } |
| 118 | |
| 119 | func BenchmarkSyncPool(b *testing.B) { |
| 120 | var wg sync.WaitGroup |
nothing calls this directly
no test coverage detected