-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverhead_test.go
57 lines (40 loc) · 1.02 KB
/
overhead_test.go
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package ratelimiter_test
import (
"context"
"testing"
"github.com/alexdyukov/ratelimiter/v2"
"github.com/alexdyukov/ratelimiter/v2/bottleneck"
)
func BenchmarkRegularBottleneck(b *testing.B) {
b.StopTimer()
rateLimiter := ratelimiter.New(bottleneck.NewRegular(overheadTestRPS, overheadTestBurst))
ctx := context.Background()
b.StartTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_ = rateLimiter.Take(ctx)
}
})
}
func BenchmarkValveBottleneck(b *testing.B) {
b.StopTimer()
rateLimiter := ratelimiter.New(bottleneck.NewValve(overheadTestRPS, overheadTestBurst))
ctx := context.Background()
b.StartTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_ = rateLimiter.Take(ctx)
}
})
}
func BenchmarkEqualizerBottleneck(b *testing.B) {
b.StopTimer()
rateLimiter := ratelimiter.New(bottleneck.NewEqualizer(overheadTestRPS, overheadTestBurst))
ctx := context.Background()
b.StartTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_ = rateLimiter.Take(ctx)
}
})
}