Debian Codegraph @

pool_bench_test.go

raw symbols SCIP
1 package re2
2
3 import (
4 "runtime"
5 "strconv"
6 "sync"
7 "sync/atomic"
8 "testing"
9 )
10
11 // BenchmarkParallelMatch measures throughput of a shared *Regexp under
12 // increasing levels of goroutine concurrency. Each MatchString call pulls
13 // a child wasm module from the shared pool; with short inputs the pool's
14 // Get/Put cost is a meaningful fraction of per-op time, so this exposes
15 // pool contention as worker count grows past GOMAXPROCS.
16 func BenchmarkParallelMatch(b *testing.B) {
17 re := MustCompileBenchmark(`\d`)
18 input := "abc7def"
19
20 nproc := runtime.GOMAXPROCS(0)
21 for _, workers := range []int{1, nproc, nproc * 4, nproc * 25} {
22 b.Run("workers="+strconv.Itoa(workers), func(b *testing.B) {
23 var counter atomic.Int64
24 target := int64(b.N)
25 var wg sync.WaitGroup
26 wg.Add(workers)
27 b.ResetTimer()
28 for range workers {
29 go func() {
30 defer wg.Done()
31 for counter.Add(1) <= target {
32 re.MatchString(input)
33 }
34 }()
35 }
36 wg.Wait()
37 })
38 }
39 }