diff options
author | Matt Joiner <anacrolix@gmail.com> | 2019-11-04 18:46:36 +1100 |
---|---|---|
committer | Matt Joiner <anacrolix@gmail.com> | 2019-11-04 18:46:36 +1100 |
commit | 6ffe9fae27d291f6239977fdf2f651fd63d6d5b1 (patch) | |
tree | ace3436cae7db21507fae2a7ffb3360cd5aae28a /bench_test.go | |
parent | Fix TestDecrement (diff) | |
download | stm-6ffe9fae27d291f6239977fdf2f651fd63d6d5b1.tar.gz stm-6ffe9fae27d291f6239977fdf2f651fd63d6d5b1.tar.xz |
Add parallel PingPong benchmark
This should help demonstrate any speed-up from removing global synchronization primitives.
Diffstat (limited to 'bench_test.go')
-rw-r--r-- | bench_test.go | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/bench_test.go b/bench_test.go index 3dbdf73..0d176d8 100644 --- a/bench_test.go +++ b/bench_test.go @@ -3,6 +3,8 @@ package stm import ( "sync" "testing" + + "github.com/anacrolix/missinggo/iter" ) func BenchmarkAtomicGet(b *testing.B) { @@ -126,7 +128,24 @@ func BenchmarkReadVarChannel(b *testing.B) { } } +func parallelPingPongs(b *testing.B, n int) { + var wg sync.WaitGroup + wg.Add(n) + for range iter.N(n) { + go func() { + defer wg.Done() + testPingPong(b, b.N, func(string) {}) + }() + } + wg.Wait() +} + +func BenchmarkPingPong4(b *testing.B) { + b.ReportAllocs() + parallelPingPongs(b, 4) +} + func BenchmarkPingPong(b *testing.B) { b.ReportAllocs() - testPingPong(b, b.N, func(string) {}) + parallelPingPongs(b, 1) } |