MCPcopy
hub / github.com/WireGuard/wireguard-go / BenchmarkWaitPoolEmpty

Function BenchmarkWaitPoolEmpty

device/pools_test.go:95–117  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

93}
94
95func 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
119func BenchmarkSyncPool(b *testing.B) {
120 var wg sync.WaitGroup

Callers

nothing calls this directly

Calls 4

GetMethod · 0.95
PutMethod · 0.95
NewWaitPoolFunction · 0.85
WaitMethod · 0.80

Tested by

no test coverage detected