-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbench_test.go
More file actions
60 lines (53 loc) · 1.62 KB
/
Copy pathbench_test.go
File metadata and controls
60 lines (53 loc) · 1.62 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
package sntable_test
import (
"bytes"
"testing"
"github.com/bsm/sntable"
)
// Benchmark_miss is the important one: it shows the bloom filter turning an
// absent-key lookup from a full block read+decompress into an in-memory bit
// check. Benchmark_hit shows the filter adds ~nothing on the hit path.
func Benchmark_bloom(b *testing.B) {
const n = 200_000
build := func(o *sntable.WriterOptions) *sntable.Reader {
var buf bytes.Buffer
w := sntable.NewWriter(&buf, o)
val := make([]byte, 16)
for i := range n {
if err := w.Append(uint64(i*2), val); err != nil {
b.Fatal(err)
}
}
if err := w.Close(); err != nil {
b.Fatal(err)
}
r, err := sntable.NewReader(bytes.NewReader(buf.Bytes()), int64(buf.Len()))
if err != nil {
b.Fatal(err)
}
return r
}
variants := []struct {
name string
opts *sntable.WriterOptions
}{
{"nobloom-snappy", &sntable.WriterOptions{Compression: sntable.SnappyCompression}},
{"nobloom-plain", &sntable.WriterOptions{Compression: sntable.NoCompression}},
{"bloom-snappy", &sntable.WriterOptions{Compression: sntable.SnappyCompression, BloomBitsPerKey: 10, BloomExpectedKeys: n}},
{"bloom-plain", &sntable.WriterOptions{Compression: sntable.NoCompression, BloomBitsPerKey: 10, BloomExpectedKeys: n}},
}
for _, v := range variants {
r := build(v.opts)
var dst []byte
b.Run(v.name+"/miss", func(b *testing.B) {
for i := 0; i < b.N; i++ {
dst, _ = r.Append(dst[:0], uint64((i%n)*2+1)) // odd = absent
}
})
b.Run(v.name+"/hit", func(b *testing.B) {
for i := 0; i < b.N; i++ {
dst, _ = r.Append(dst[:0], uint64((i%n)*2)) // even = present
}
})
}
}