-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory_bench_test.go
More file actions
117 lines (100 loc) · 2.16 KB
/
Copy pathmemory_bench_test.go
File metadata and controls
117 lines (100 loc) · 2.16 KB
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
package wal_test
import (
"context"
"strconv"
"testing"
"github.com/mgurevin/wal"
)
func BenchmarkMemoryWALAppendVolatile4KiB(b *testing.B) {
payload := make([]byte, 4<<10)
records := make([]wal.Record, b.N)
for index := range records {
records[index] = wal.Record{
ID: strconv.Itoa(index),
Data: payload,
}
}
log, err := wal.NewMemory(wal.MemoryConfig{
MaxBytes: int64(len(records)) * int64(len(payload)+32),
MaxRecords: len(records),
MaxRecordBytes: len(payload),
MaxReadEntries: 1,
})
if err != nil {
b.Fatal(err)
}
defer closeTest(b, log.Close)
b.ReportAllocs()
b.ResetTimer()
// Keep b.N: the WAL and unique record IDs must be sized before timing starts.
for index := 0; index < b.N; index++ {
if _, err := log.Append(
context.Background(),
records[index],
wal.Volatile,
); err != nil {
b.Fatal(err)
}
}
}
func BenchmarkMemoryWALFlush(b *testing.B) {
log, err := wal.NewMemory(wal.MemoryConfig{
MaxBytes: 1 << 20,
MaxRecords: 128,
MaxRecordBytes: 1 << 10,
MaxReadEntries: 128,
})
if err != nil {
b.Fatal(err)
}
defer closeTest(b, log.Close)
if _, err := log.Append(
context.Background(),
wal.Record{ID: "one", Data: []byte("payload")},
wal.Volatile,
); err != nil {
b.Fatal(err)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
b.ReportAllocs()
for b.Loop() {
watermark, err := log.Flush(ctx, wal.Volatile)
if err != nil || watermark != 1 {
b.Fatalf("Flush = (%d, %v)", watermark, err)
}
}
}
func BenchmarkMemoryWALScan10000(b *testing.B) {
const records = 10_000
log, err := wal.NewMemory(wal.MemoryConfig{
MaxBytes: 1 << 20,
MaxRecords: records,
MaxRecordBytes: 32,
MaxReadEntries: records,
})
if err != nil {
b.Fatal(err)
}
for index := range records {
if _, err := log.Append(context.Background(),
wal.Record{
ID: strconv.Itoa(index),
Data: []byte("record"),
},
wal.Volatile); err != nil {
b.Fatal(err)
}
}
b.ReportAllocs()
for b.Loop() {
if err := log.Scan(
context.Background(),
0,
records,
func(wal.Entry) error { return nil },
); err != nil {
b.Fatal(err)
}
}
}