-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap_bench_test.go
More file actions
118 lines (105 loc) · 2.08 KB
/
map_bench_test.go
File metadata and controls
118 lines (105 loc) · 2.08 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package hmap
import (
"testing"
)
func BenchmarkMap_NewMap(b *testing.B) {
for i := 0; i < b.N; i++ {
NewMap[string, int](10)
}
}
func BenchmarkMap_Len(b *testing.B) {
m := NewMap[string, int](10)
for i := 0; i < b.N; i++ {
m.Len()
}
}
func BenchmarkMap_Load(b *testing.B) {
m := NewMap[string, int](10)
m.Store("key1", 1)
b.ResetTimer()
for i := 0; i < b.N; i++ {
m.Load("key1")
}
}
func BenchmarkMap_Swap(b *testing.B) {
m := NewMap[string, int](10)
m.Store("key1", 1)
b.ResetTimer()
for i := 0; i < b.N; i++ {
m.Swap("key1", 2)
}
}
func BenchmarkMap_Store(b *testing.B) {
m := NewMap[string, int](10)
b.ResetTimer()
for i := 0; i < b.N; i++ {
m.Store("key1", 1)
}
}
func BenchmarkMap_LoadOrStore(b *testing.B) {
m := NewMap[string, int](10)
b.ResetTimer()
for i := 0; i < b.N; i++ {
m.LoadOrStore("key1", 1)
}
}
func BenchmarkMap_Delete(b *testing.B) {
m := NewMap[string, int](10)
m.Store("key1", 1)
b.ResetTimer()
for i := 0; i < b.N; i++ {
m.Delete("key1")
m.Store("key1", 1)
}
}
func BenchmarkMap_LoadAndDelete(b *testing.B) {
m := NewMap[string, int](10)
m.Store("key1", 1)
b.ResetTimer()
for i := 0; i < b.N; i++ {
m.LoadAndDelete("key1")
m.Store("key1", 1)
}
}
func BenchmarkMap_Range(b *testing.B) {
m := NewMap[string, int](10)
for i := 0; i < 100; i++ {
m.Store("key"+string(rune(i)), i)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
m.Range(func(k string, v int) bool {
return true
})
}
}
func BenchmarkMap_Clean(b *testing.B) {
m := NewMap[string, int](10)
for i := 0; i < 100; i++ {
m.Store("key"+string(rune(i)), i)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
m.Clean()
for j := 0; j < 100; j++ {
m.Store("key"+string(rune(j)), j)
}
}
}
func BenchmarkMap_CompareAndSwap(b *testing.B) {
m := NewMap[string, int](10)
m.Store("key1", 1)
b.ResetTimer()
for i := 0; i < b.N; i++ {
m.CompareAndSwap("key1", 1, 2)
}
}
func BenchmarkMap_CompareAndDelete(b *testing.B) {
m := NewMap[string, int](10)
m.Store("key1", 1)
b.ResetTimer()
for i := 0; i < b.N; i++ {
m.CompareAndDelete("key1", 1)
m.Store("key1", 1)
}
}