forked from fuyao-w/papillon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
61 lines (56 loc) · 1.23 KB
/
main_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
package papillon
import (
"sync/atomic"
"testing"
"time"
)
func BenchmarkPoolSlice(b *testing.B) {
b.Run("allocate", func(b *testing.B) {
for i := 0; i < b.N; i++ {
list := make([]uint64, 0, 4)
for i := uint64(0); i < 4; i++ {
list = append(list, i)
}
}
})
b.Run("not allocate", func(b *testing.B) {
var x = make([]uint64, 0)
for i := 0; i < b.N; i++ {
for i := uint64(0); i < 4; i++ {
x = append(x, i)
}
x = x[:0]
}
})
}
func BenchmarkPoolAppendEntriesRequest(b *testing.B) {
r := Raft{localInfo: ServerInfo{
Suffrage: 0,
Addr: "1",
ID: "1",
}, currentTerm: new(atomic.Uint64),
//appendEntriesPool: initAppendEntriesPool(),
commitIndex: new(atomic.Uint64),
}
r.currentTerm.Store(111)
r.commitIndex.Store(1231)
b.Run("allocate", func(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = &AppendEntryRequest{
RPCHeader: r.buildRPCHeader(),
Term: r.getCurrentTerm(),
LeaderCommit: r.getCommitIndex(),
}
time.Sleep(10 * time.Millisecond)
}
})
b.Run("not allocate", func(b *testing.B) {
for i := 0; i < b.N; i++ {
func() {
//_, recycle := r.retrieveAppendEntryRequest()
//defer recycle()
//time.Sleep(10 * time.Millisecond)
}()
}
})
}