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