From 5f6607152a96b85f1518028b8f1ee1ef1aefda75 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Thu, 23 Jan 2025 09:54:11 -0300 Subject: Move benchmarks from tests/stm.go to tests/benchmarks/* --- tests/benchmarks/increment-stm/stm.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/benchmarks/increment-stm/stm.go (limited to 'tests/benchmarks/increment-stm/stm.go') diff --git a/tests/benchmarks/increment-stm/stm.go b/tests/benchmarks/increment-stm/stm.go new file mode 100644 index 0000000..9f12eb1 --- /dev/null +++ b/tests/benchmarks/increment-stm/stm.go @@ -0,0 +1,33 @@ +package stm + +import ( + "flag" +) + + + +var nFlag = flag.Int( + "n", + 1_000, + "The number of iterations to execute", +) + +func MainTest() { + flag.Parse() + n := *nFlag + + for i := 0; i < n; i++ { + // swap 1000 goroutines that each increment v by 1 + v := NewVar(0) + for i := 0; i < 1000; i++ { + go Atomically(VoidOperation(func(tx *Tx) { + v.Set(tx, v.Get(tx) + 1) + })) + } + + // wait for v to reach 1000 + Atomically(VoidOperation(func(tx *Tx) { + tx.Assert(v.Get(tx) == 1000) + })) + } +} -- cgit v1.2.3