From 6ffe9fae27d291f6239977fdf2f651fd63d6d5b1 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Mon, 4 Nov 2019 18:46:36 +1100 Subject: Add parallel PingPong benchmark This should help demonstrate any speed-up from removing global synchronization primitives. --- bench_test.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'bench_test.go') 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) } -- cgit v1.2.3