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

Function BenchmarkWaitPool

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

Source from the content-addressed store, hash-verified

69}
70
71func 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
95func BenchmarkWaitPoolEmpty(b *testing.B) {
96 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