(b *testing.B)
| 69 | } |
| 70 | |
| 71 | func BenchmarkWaitPool(b *testing.B) { |
| 72 | var wg sync.WaitGroup |
| 73 | var trials atomic.Int32 |
| 74 | trials.Store(int32(b.N)) |
| 75 | workers := runtime.NumCPU() + 2 |
| 76 | if workers-4 <= 0 { |
| 77 | b.Skip("Not enough cores") |
| 78 | } |
| 79 | p := NewWaitPool(uint32(workers-4), func() any { return make([]byte, 16) }) |
| 80 | wg.Add(workers) |
| 81 | b.ResetTimer() |
| 82 | for i := 0; i < workers; i++ { |
| 83 | go func() { |
| 84 | defer wg.Done() |
| 85 | for trials.Add(-1) > 0 { |
| 86 | x := p.Get() |
| 87 | time.Sleep(time.Duration(rand.Intn(100)) * time.Microsecond) |
| 88 | p.Put(x) |
| 89 | } |
| 90 | }() |
| 91 | } |
| 92 | wg.Wait() |
| 93 | } |
| 94 | |
| 95 | func BenchmarkWaitPoolEmpty(b *testing.B) { |
| 96 | var wg sync.WaitGroup |
nothing calls this directly
no test coverage detected