-
Notifications
You must be signed in to change notification settings - Fork 0
/
map_benchmark_test.go
75 lines (66 loc) · 1.75 KB
/
map_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package ordered_sync_map_test
import (
"fmt"
"testing"
mp "github.com/m-murad/ordered-sync-map"
)
func getPopulatedOrderedSyncMap(size int) *mp.Map[any, any] {
m := mp.New[any, any]()
populateOrderedSyncMap(m, size)
return m
}
func populateOrderedSyncMap(m *mp.Map[any, any], size int) {
for i := 0; i < size; i++ {
m.Put(i, i)
}
}
func BenchmarkOrderedSyncMapGet(b *testing.B) {
mapSize := 1000
m := initMap()
populateOrderedSyncMap(m, mapSize)
for n := 1; n <= 10; n++ {
b.Run(fmt.Sprintf("Get form ordered_sync_map - %d", n), func(b *testing.B) {
for i := 0; i < b.N; i++ {
_, _ = m.Get(b.N % mapSize)
}
})
}
}
func BenchmarkOrderedSyncMapPut(b *testing.B) {
for n := 1; n <= 10; n++ {
m := mp.New[any, any]()
b.Run(fmt.Sprintf("Put in ordered_sync_map - %d", n), func(b *testing.B) {
populateOrderedSyncMap(m, b.N)
})
}
}
func BenchmarkOrderedSyncMapDelete(b *testing.B) {
for n := 1; n < 10; n++ {
b.Run(fmt.Sprintf("Delete form ordered_sync_map - %d", n), func(b *testing.B) {
size := b.N
m := getPopulatedOrderedSyncMap(size)
b.ResetTimer()
for i := 0; i < size; i++ {
m.Delete(i)
}
})
}
}
func BenchmarkOrderedSyncMapUnorderedTraversal(b *testing.B) {
for n := 1; n < 5; n++ {
b.Run(fmt.Sprintf("Traverse ordered_sync_map randomly - %d", n), func(b *testing.B) {
m := getPopulatedOrderedSyncMap(b.N)
b.ResetTimer()
m.UnorderedRange(func(key interface{}, value interface{}) {})
})
}
}
func BenchmarkOrderedSyncMapOrderedTraversal(b *testing.B) {
for n := 1; n < 5; n++ {
b.Run(fmt.Sprintf("Traverse ordered_sync_map in order - %d", n), func(b *testing.B) {
m := getPopulatedOrderedSyncMap(b.N)
b.ResetTimer()
m.OrderedRange(func(key interface{}, value interface{}) {})
})
}
}