-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench_test.go
51 lines (48 loc) · 849 Bytes
/
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
package cdb
import (
"strconv"
"testing"
)
func BenchmarkCdb_GetValue(b *testing.B) {
b.StopTimer()
w := NewMemoryWriter()
for i := 0; i < b.N; i++ {
err := w.WriteKeyValue([]byte(strconv.Itoa(i)), []byte(strconv.Itoa(i)))
if err != nil {
panic(err)
}
}
db, err := w.Freeze()
if err != nil {
panic(err)
}
b.StartTimer()
for i := 0; i < b.N; i++ {
key := strconv.Itoa(i)
vb, err := db.GetValue([]byte(key))
if err != nil {
panic(err)
}
if string(vb) != key {
panic(string(vb))
}
}
}
func BenchmarkCdb_GetValue2(b *testing.B) {
b.StopTimer()
db := map[string]string{}
for i := 0; i < b.N; i++ {
db[strconv.Itoa(i)] = strconv.Itoa(i)
}
b.StartTimer()
for i := 0; i < b.N; i++ {
key := strconv.Itoa(i)
value, ok := db[key]
if !ok {
panic(key)
}
if value != key {
panic(value)
}
}
}