-
Notifications
You must be signed in to change notification settings - Fork 8
/
benchmark_test.go
92 lines (78 loc) · 1.56 KB
/
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package barrel_test
import (
"os"
"strings"
"testing"
barrel "github.com/mr-karan/barreldb"
)
func BenchmarkPut(b *testing.B) {
// Create a temp directory for running tests.
tmpDir, err := os.MkdirTemp("", "barreldb")
if err != nil {
b.Fatal(err)
}
defer os.RemoveAll(tmpDir)
scenarios := map[string][]barrel.Config{
"AlwaysSync": {barrel.WithDir(tmpDir), barrel.WithAlwaysSync()},
"DisableSync": {barrel.WithDir(tmpDir)},
}
for sc, cfg := range scenarios {
brl, err := barrel.Init(cfg...)
if err != nil {
b.Fatal(err)
}
b.Run(sc, func(b *testing.B) {
// Size of each value -> 4kb.
b.SetBytes(int64(4096))
b.ReportAllocs()
var (
key = "hello"
val = []byte(strings.Repeat(" ", 4096))
)
b.ResetTimer()
for i := 0; i < b.N; i++ {
err = brl.Put(key, val)
if err != nil {
b.Fatal(err)
}
}
b.StopTimer()
})
brl.Shutdown()
}
}
func BenchmarkGet(b *testing.B) {
// Create a temp directory for running tests.
tmpDir, err := os.MkdirTemp("", "barreldb")
if err != nil {
b.Fatal(err)
}
defer os.RemoveAll(tmpDir)
brl, err := barrel.Init(barrel.WithDir(tmpDir))
if err != nil {
b.Fatal(err)
}
defer brl.Shutdown()
// Size of each value -> 4kb.
b.SetBytes(int64(4096))
b.ReportAllocs()
var (
key = "hello"
val = []byte(strings.Repeat(" ", 4096))
)
// Put dummy keys.
for i := 0; i < b.N; i++ {
err = brl.Put(key, val)
if err != nil {
b.Fatal(err)
}
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := brl.Get(key)
if err != nil {
b.Fatal(err)
}
}
b.StopTimer()
}