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

Function BenchmarkSyncPool

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

Source from the content-addressed store, hash-verified

117}
118
119func BenchmarkSyncPool(b *testing.B) {
120 var wg sync.WaitGroup
121 var trials atomic.Int32
122 trials.Store(int32(b.N))
123 workers := runtime.NumCPU() + 2
124 if workers-4 <= 0 {
125 b.Skip("Not enough cores")
126 }
127 p := sync.Pool{New: func() any { return make([]byte, 16) }}
128 wg.Add(workers)
129 b.ResetTimer()
130 for i := 0; i < workers; i++ {
131 go func() {
132 defer wg.Done()
133 for trials.Add(-1) > 0 {
134 x := p.Get()
135 time.Sleep(time.Duration(rand.Intn(100)) * time.Microsecond)
136 p.Put(x)
137 }
138 }()
139 }
140 wg.Wait()
141}

Callers

nothing calls this directly

Calls 3

GetMethod · 0.80
PutMethod · 0.80
WaitMethod · 0.80

Tested by

no test coverage detected