-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark_test.go
57 lines (49 loc) · 1.17 KB
/
benchmark_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 timer_test
import (
"testing"
"time"
"github.com/RussellLuo/timingwheel"
"github.com/TarsCloud/TarsGo/tars/util/rtimer"
timer "github.com/flyaways/timer"
)
const (
gearSize time.Duration = time.Millisecond * 5
afterDuration time.Duration = time.Millisecond * 100
wheelNum int = 20
)
// BenchmarkTimeWheel benchmarks timewheel.
func BenchmarkFlyawaysTimer(b *testing.B) {
t := timer.New(wheelNum, gearSize)
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
t.After(afterDuration)
}
})
}
// BenchmarkTimeWheel benchmarks timewheel.
func BenchmarkTarsGoTimer(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
rtimer.After(afterDuration)
}
})
}
// BenchmarkTimeBase benchmark origin timer.
func BenchmarkOfficalTimer(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
time.After(afterDuration)
}
})
}
// BenchmarkRussellLuoTimer benchmark timewheel.
func BenchmarkRussellLuoTimer(b *testing.B) {
tw := timingwheel.NewTimingWheel(gearSize, int64(wheelNum))
tw.Start()
defer tw.Stop()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
tw.AfterFunc(afterDuration, func() {})
}
})
}