diff options
Diffstat (limited to 'tests/benchmarks/increment-channel/stm.go')
-rw-r--r-- | tests/benchmarks/increment-channel/stm.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/benchmarks/increment-channel/stm.go b/tests/benchmarks/increment-channel/stm.go new file mode 100644 index 0000000..0d17a86 --- /dev/null +++ b/tests/benchmarks/increment-channel/stm.go @@ -0,0 +1,35 @@ +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++ { + c := make(chan int, 1) + c <- 0 + for i := 0; i < 1000; i++ { + go func() { + c <- 1 + <-c + }() + } + for { + read := <-c + if read == 1000 { + break + } + c <- read + } + } +} |