aboutsummaryrefslogtreecommitdiff
path: root/tests/benchmarks/increment-mutex
diff options
context:
space:
mode:
Diffstat (limited to 'tests/benchmarks/increment-mutex')
l---------tests/benchmarks/increment-mutex/main.go1
-rw-r--r--tests/benchmarks/increment-mutex/stm.go43
2 files changed, 44 insertions, 0 deletions
diff --git a/tests/benchmarks/increment-mutex/main.go b/tests/benchmarks/increment-mutex/main.go
new file mode 120000
index 0000000..f67563d
--- /dev/null
+++ b/tests/benchmarks/increment-mutex/main.go
@@ -0,0 +1 @@
+../../main.go \ No newline at end of file
diff --git a/tests/benchmarks/increment-mutex/stm.go b/tests/benchmarks/increment-mutex/stm.go
new file mode 100644
index 0000000..9a442a5
--- /dev/null
+++ b/tests/benchmarks/increment-mutex/stm.go
@@ -0,0 +1,43 @@
+package stm
+
+import (
+ "flag"
+ "sync"
+)
+
+
+
+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++ {
+ v := 0
+ var mu sync.Mutex
+ for i := 0; i < 1000; i++ {
+ go func() {
+ mu.Lock()
+ defer mu.Unlock()
+ v++
+ }()
+ }
+
+ for {
+ var read int
+ func() {
+ mu.Lock()
+ defer mu.Unlock()
+ read = v
+ }()
+ if read == 1000 {
+ break
+ }
+ }
+ }
+}