-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
writer_bench_test.go
55 lines (45 loc) · 1.26 KB
/
writer_bench_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
package parquet
import (
"fmt"
"math/rand"
"os"
"testing"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
"github.com/stretchr/testify/require"
)
// BenchmarkParquetWriter benchmarks the Writer.AddData operation.
func BenchmarkParquetWriter(b *testing.B) {
rng := rand.New(rand.NewSource(timeutil.Now().UnixNano()))
// Create a row size of 2KiB.
numCols := 16
datumSizeBytes := 128
sch := newColSchema(numCols)
for i := 0; i < numCols; i++ {
sch.columnTypes[i] = types.String
sch.columnNames[i] = fmt.Sprintf("col%d", i)
}
datums := make([]tree.Datum, numCols)
for i := 0; i < numCols; i++ {
p := make([]byte, datumSizeBytes)
_, _ = rng.Read(p)
tree.NewDBytes(tree.DBytes(p))
datums[i] = tree.NewDString(string(p))
}
fileName := "BenchmarkParquetWriter"
f, err := os.CreateTemp("", fileName)
require.NoError(b, err)
schemaDef, err := NewSchema(sch.columnNames, sch.columnTypes)
require.NoError(b, err)
writer, err := NewWriter(schemaDef, f)
require.NoError(b, err)
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
err := writer.AddData(datums)
require.NoError(b, err)
}
err = writer.Close()
require.NoError(b, err)
}