-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_bench_test.go
134 lines (111 loc) · 2.4 KB
/
db_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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package fifodb
import (
"os"
"strconv"
"testing"
"time"
)
func BenchmarkDBPut16(b *testing.B) {
benchmarkDBPut(16, b)
}
func BenchmarkDBPut32(b *testing.B) {
benchmarkDBPut(32, b)
}
func BenchmarkDBPut64(b *testing.B) {
benchmarkDBPut(64, b)
}
func BenchmarkDBPut128(b *testing.B) {
benchmarkDBPut(128, b)
}
func BenchmarkDBPut256(b *testing.B) {
benchmarkDBPut(256, b)
}
func BenchmarkDBPut1024(b *testing.B) {
benchmarkDBPut(1024, b)
}
func BenchmarkDBPut4096(b *testing.B) {
benchmarkDBPut(4096, b)
}
func BenchmarkDBPut16384(b *testing.B) {
benchmarkDBPut(16384, b)
}
func BenchmarkDBPut65536(b *testing.B) {
benchmarkDBPut(65536, b)
}
func BenchmarkDBGet16(b *testing.B) {
// benchmarkDBGet(16, b)
}
func BenchmarkDBGet64(b *testing.B) {
// benchmarkDBGet(64, b)
}
func BenchmarkDBGet256(b *testing.B) {
// benchmarkDBGet(256, b)
}
func BenchmarkDBGet1024(b *testing.B) {
// benchmarkDBGet(1024, b)
}
func BenchmarkDBGet4096(b *testing.B) {
// benchmarkDBGet(4096, b)
}
func BenchmarkDBGet16384(b *testing.B) {
// benchmarkDBGet(16384, b)
}
func BenchmarkDBGet65536(b *testing.B) {
// benchmarkDBGet(65536, b)
}
//func BenchmarkDBPutMult16(b *testing.B) {
// benchmarkDBPutMulti(16, b)
//}
//func BenchmarkDBPutMult64(b *testing.B) {
// benchmarkDBPutMulti(64, b)
//}
func benchmarkDBPut(size int64, b *testing.B) {
b.SetBytes(size)
opt := DefaultOptions
opt.Path = "test/bench_db" + strconv.Itoa(int(size)) + "_" + strconv.Itoa(b.N) + "_" + strconv.Itoa(int(time.Now().Unix()))
db, _, err := Open(opt)
if err != nil {
b.Fatal(err)
}
data := make([]byte, size)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _, err := db.Push(data)
if err != nil {
b.Fatal("Unexpected error on benchmark", err)
}
}
b.StopTimer()
//err = db.Close()
//if err != nil {
// b.Fatal(err)
//}
err = os.RemoveAll(db.GetPath())
if err != nil {
b.Fatal(err)
}
}
func benchmarkDBGet(size int64, b *testing.B) {
b.StopTimer()
dqName := "test/bench_disk_queue_put_" + strconv.Itoa(int(size)) + "_" + strconv.Itoa(b.N) + "_" + strconv.Itoa(int(time.Now().Unix()))
opt := DefaultOptions
opt.Path = dqName
st, _, _ := Open(opt)
b.SetBytes(size)
data := make([]byte, size)
defer st.Close()
for i := 0; i < b.N; i++ {
_, _, err := st.Push(data)
if err != nil {
panic(err)
}
}
st.Sync()
b.StartTimer()
for i := 0; i < b.N; i++ {
_, _, _, err := st.Pop()
if err != nil {
panic(i)
}
}
}