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. --- stm_test.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'stm_test.go') diff --git a/stm_test.go b/stm_test.go index 28f56ec..aeb0907 100644 --- a/stm_test.go +++ b/stm_test.go @@ -1,8 +1,11 @@ package stm import ( + "sync" "testing" "time" + + _ "github.com/anacrolix/envpprof" ) func TestDecrement(t *testing.T) { @@ -220,7 +223,9 @@ func testPingPong(t testing.TB, n int, afterHit func(string)) { doneVar := NewVar(false) hits := NewVar(0) ready := NewVar(true) // The ball is ready for hitting. + var wg sync.WaitGroup bat := func(from, to interface{}, noise string) { + defer wg.Done() for !Atomically(func(tx *Tx) { if tx.Get(doneVar).(bool) { tx.Return(true) @@ -238,12 +243,14 @@ func testPingPong(t testing.TB, n int, afterHit func(string)) { AtomicSet(ready, true) } } + wg.Add(2) go bat(false, true, "ping!") go bat(true, false, "pong!") Atomically(func(tx *Tx) { tx.Assert(tx.Get(hits).(int) >= n) tx.Set(doneVar, true) }) + wg.Wait() } func TestPingPong(t *testing.T) { -- cgit v1.2.3