-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathbench_test.go
83 lines (73 loc) · 1.54 KB
/
bench_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package skipmap
import (
"testing"
"github.com/zhangyunhao116/fastrand"
)
func BenchmarkLoadOrStoreExist(b *testing.B) {
m := NewInt[int]()
m.Store(1, 1)
b.ResetTimer()
b.RunParallel(func(p *testing.PB) {
for p.Next() {
m.LoadOrStore(1, 1)
}
})
}
func BenchmarkLoadOrStoreLazyExist(b *testing.B) {
m := NewInt[int]()
m.Store(1, 1)
b.ResetTimer()
b.RunParallel(func(p *testing.PB) {
for p.Next() {
m.LoadOrStoreLazy(1, func() int { return 1 })
}
})
}
func BenchmarkLoadOrStoreExistSingle(b *testing.B) {
m := NewInt[int]()
m.Store(1, 1)
b.ResetTimer()
for i := 0; i < b.N; i++ {
m.LoadOrStore(1, 1)
}
}
func BenchmarkLoadOrStoreLazyExistSingle(b *testing.B) {
m := NewInt[int]()
m.Store(1, 1)
b.ResetTimer()
for i := 0; i < b.N; i++ {
m.LoadOrStoreLazy(1, func() int { return 1 })
}
}
func BenchmarkLoadOrStoreRandom(b *testing.B) {
m := NewInt[int]()
b.ResetTimer()
b.RunParallel(func(p *testing.PB) {
for p.Next() {
m.LoadOrStore(fastrand.Int(), 1)
}
})
}
func BenchmarkLoadOrStoreLazyRandom(b *testing.B) {
m := NewInt[int]()
b.ResetTimer()
b.RunParallel(func(p *testing.PB) {
for p.Next() {
m.LoadOrStoreLazy(fastrand.Int(), func() int { return 1 })
}
})
}
func BenchmarkLoadOrStoreRandomSingle(b *testing.B) {
m := NewInt[int]()
b.ResetTimer()
for i := 0; i < b.N; i++ {
m.LoadOrStore(fastrand.Int(), 1)
}
}
func BenchmarkLoadOrStoreLazyRandomSingle(b *testing.B) {
m := NewInt[int]()
b.ResetTimer()
for i := 0; i < b.N; i++ {
m.LoadOrStoreLazy(fastrand.Int(), func() int { return 1 })
}
}