-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.go
57 lines (43 loc) · 1.22 KB
/
benchmark.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
package cleantone
import (
"fmt"
"math/rand"
"os"
"testing"
"time"
)
var config = DBConfig{
DataFormat: DataFormat.CSV,
DataPath: "/Users/davy/davy/go_playground/kv_db/data",
RotateThreshold: 100 * FileSize.MB,
}
var TestDB = NewDB(config)
var INDEX = map[string]string{}
var CsvFile *os.File
var KEY = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
var VALUE = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
func BenchmarkSetSingleKey(b *testing.B) {
// 设置随机数种子
rand.Seed(time.Now().UnixNano())
for j := 0; j < b.N; j++ {
TestDB.Set(KEY, VALUE)
}
}
func BenchmarkReadKey(b *testing.B) {
// 设置随机数种子
rand.Seed(time.Now().UnixNano())
for j := 0; j < b.N; j++ {
TestDB.Get("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
}
}
func BenchmarkWriteCSV(b *testing.B) {
rand.Seed(time.Now().UnixNano())
for j := 0; j < b.N; j++ {
INDEX[KEY] = VALUE
CsvFile.WriteString(fmt.Sprintf("%s,%s\n", KEY, VALUE))
}
}
func main() {
CsvFile, _ = os.OpenFile("./test.csv", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
testing.Benchmark(BenchmarkSetSingleKey)
}