-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark_test.go
More file actions
53 lines (44 loc) · 1.15 KB
/
Copy pathbenchmark_test.go
File metadata and controls
53 lines (44 loc) · 1.15 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
package wal_test
import (
"math/rand"
"os"
"testing"
"time"
"github.com/fgrosse/wal"
"github.com/fgrosse/wal/waltest"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)
var exampleBenchmarkEntries [1000]*waltest.ExampleEntry1
func init() {
seed := time.Now().UnixMilli()
rng := rand.New(rand.NewSource(seed))
for i := range exampleBenchmarkEntries {
exampleBenchmarkEntries[i] = &waltest.ExampleEntry1{
ID: uint32(i + 1),
Point: []float32{rng.Float32() * 10, rng.Float32() * 10},
}
}
}
func BenchmarkWAL_Write(b *testing.B) {
path := b.TempDir()
conf := wal.DefaultConfiguration()
w, err := wal.New(path, conf, waltest.ExampleEntries, zap.NewNop())
require.NoError(b, err)
b.ResetTimer()
for i := 0; i < b.N; i++ {
e := exampleBenchmarkEntries[i%len(exampleBenchmarkEntries)]
_, _ = w.Write(e)
}
}
func BenchmarkSegmentReader_SeekEnd(b *testing.B) {
for i := 0; i < b.N; i++ {
f, err := os.Open("testdata/segment.wal")
require.NoError(b, err)
b.Cleanup(func() { _ = f.Close() })
r, err := wal.NewSegmentReader(f, waltest.ExampleEntries)
require.NoError(b, err)
_, err = r.SeekEnd()
require.NoError(b, err)
}
}