-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdouble_test.go
87 lines (70 loc) · 1.62 KB
/
double_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
package main
import (
"bytes"
"context"
"io"
"math/rand"
"os"
"testing"
)
type doubleHolder struct {
D float64 `parquet:"d"`
}
func TestDoubleWriter(t *testing.T) {
values := []doubleHolder{{1}, {3}, {1}, {6}, {7}, {9}, {3}}
buf := bytes.NewBuffer(nil)
err := write(context.Background(), buf, values)
if err != nil {
t.Fatal(err)
}
data := buf.Bytes()
os.WriteFile("/tmp/out.parquet", data, 0666)
f := newFile(data)
readValues := make([]doubleHolder, f.NumRows())
parse(f, readValues)
if len(values) != len(readValues) {
t.Fatal("bad length")
}
for i := range values {
if values[i] != readValues[i] {
t.Fatal("Bad at index", i)
}
}
}
func doubleValues(n int) []doubleHolder {
r := rand.New(rand.NewSource(0))
values := make([]doubleHolder, n)
for i := range values {
values[i].D = r.Float64()
}
return values
}
// BenchmarkDoubleWriterPlain-16 2876 383738 ns/op 804600 B/op 88 allocs/op
func BenchmarkDoubleWriterPlain(b *testing.B) {
values := doubleValues(100000)
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
err := write(context.Background(), io.Discard, values)
if err != nil {
b.Fatal(err)
}
}
}
// BenchmarkDoubleReaderPlain-16 1929 581847 ns/op 1607204 B/op 36 allocs/op
func BenchmarkDoubleReaderPlain(b *testing.B) {
values := doubleValues(100000)
buf := bytes.NewBuffer(nil)
err := write(context.Background(), buf, values)
if err != nil {
b.Fatal(err)
}
data = buf.Bytes()
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
f := newFile(data)
out := make([]doubleHolder, f.NumRows())
parse(f, out)
}
}