aboutsummaryrefslogtreecommitdiff
path: root/tests/benchmarks/allow-n/stm.go
blob: 2b0b34259d5abcfb154a2e7f898538ab190f86fa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package stm

import (
	"flag"
	"time"
	"sync"
)



var nFlag = flag.Int(
	"n",
	1_000,
	"The number of iterations to execute",
)

func MainTest() {
	flag.Parse()
	n := *nFlag

	var wg sync.WaitGroup
	wg.Add(n)
	lim := NewLimiter(Every(1*time.Second), 1)
	for i := 0; i < n; i++ {
		go func() {
			lim.AllowN(1)
			wg.Done()
		}()
	}
	wg.Wait()
}