-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_banchmark_test.go
64 lines (56 loc) · 1.29 KB
/
main_banchmark_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
package gocollections
import (
"fmt"
"testing"
"time"
)
var gs string
func BenchmarkTimeExpiredList(b *testing.B) {
var s string
for i := 0; i < b.N; i++ {
s = fmt.Sprint("hello")
}
gs = s
}
func BenchmarkSlice(b *testing.B) {
b.ReportAllocs()
var list []string
for i := 0; i < b.N; i++ {
list = append(list, fmt.Sprintf("test-%d", i))
}
}
func BenchmarkTimeExpiredList_Add(b *testing.B) {
tlist := NewTimeExpiredList[string](1 * time.Second)
defer tlist.Discard()
for i := 0; i < b.N; i++ {
tlist.Add(fmt.Sprintf("test-%d", i))
}
}
func BenchmarkTimeExpiredList_Expired(b *testing.B) {
tlist := &timeExpiredList[string]{
duration: 1 * time.Nanosecond,
data: []expiredElement[string]{},
dataString: []string{},
quitChan: make(chan struct{}),
}
for i := 0; i < b.N; i++ {
tlist.Add(fmt.Sprintf("test-%d", i))
}
tlist.removeExpired()
}
func BenchmarkTimeExpiredList_Size(b *testing.B) {
tlist := NewTimeExpiredList[string](10 * time.Millisecond)
defer tlist.Discard()
for i := 0; i < b.N; i++ {
tlist.Add(fmt.Sprintf("test-%d", i))
}
tlist.Size()
}
func BenchmarkTimeExpiredMap_Clear(b *testing.B) {
tmap := NewTimeExpiredMap[string, string](5 * time.Second)
for i := 0; i < b.N; i++ {
key := fmt.Sprintf("test-%d", i)
tmap.Add(key, key)
}
tmap.Clear()
}