-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathzstore_test.go
110 lines (83 loc) · 1.76 KB
/
zstore_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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package simstore
import (
"math/rand"
"sort"
"testing"
"time"
"unsafe"
)
func TestCompress(t *testing.T) {
const signatures = 1 << 20
var z zstore
u := make(u64slice, signatures)
for i := range u {
u[i] = uint64(rand.Int63())
z.add(u[i])
}
sort.Sort(u)
z.finish()
sz := len(u) * int(unsafe.Sizeof(u[0]))
csz := len(z.b)
t.Logf("entries=%d size=%d compressed=%d savings=%d%%\n", signatures, sz, csz, int(100-100*float64(csz)/float64(sz)))
var d u64slice
var err error
var totalDuration time.Duration
var blocks int
for i := range u {
if len(d) == 0 {
t0 := time.Now()
d, err = z.decompressBlock(blocks)
totalDuration += time.Since(t0)
blocks++
if err != nil {
t.Errorf("decompress err = %+v\n", err)
}
}
if u[i] != d[0] {
t.Fatalf("d[%d]=%x, want %x\n", i, d[0], u[i])
}
d = d[1:]
}
t.Logf("blocks=%d, average decompression time %v", blocks, totalDuration/time.Duration(blocks))
}
func BenchmarkDecompress(b *testing.B) {
const signatures = 1 << 20
var z zstore
u := make(u64slice, signatures)
for i := range u {
u[i] = uint64(rand.Int63())
z.add(u[i])
}
sort.Sort(u)
z.finish()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for j := 0; j < len(z.index); j++ {
z.decompressBlock(j)
}
}
}
func TestDuplicateSignatures(t *testing.T) {
const signatures = 20
var z zstore
u := make(u64slice, signatures)
for i := range u {
u[i] = uint64(rand.Int63())
z.add(u[i])
z.add(u[i])
}
sort.Sort(u)
z.finish()
d, err := z.decompressBlock(0)
if err != nil {
t.Fatalf("error during decompressBlock: %v\n", err)
}
if len(d) != len(u) {
t.Fatalf("len(d)=%d len(u)=%d\n", len(d), len(u))
}
for i := range d {
if d[i] != u[i] {
t.Errorf("d[%d]=%x u[%d]=%x\n", i, d[i], i, u[i])
}
}
}