-
Notifications
You must be signed in to change notification settings - Fork 2
/
chiv_benchmark_test.go
82 lines (66 loc) · 1.54 KB
/
chiv_benchmark_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
// +build benchmark
package chiv_test
import (
"context"
"database/sql"
"fmt"
"testing"
"gavincabbage.com/chiv"
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
)
func BenchmarkArchiver_Archive(b *testing.B) {
var (
benchmarks = []int{1, 10, 100, 1_000, 5_000, 10_000, 1_000_000}
ctx = context.Background()
rows = &benchmarkRows{
columnTypes: make([]*sql.ColumnType, 10),
column: sql.RawBytes("column_value"),
}
uploader = &uploader{}
bucket = "benchmark_bucket"
format = chiv.WithFormat(format(&benchmarkFormatter{}))
)
for _, count := range benchmarks {
rows.max = count
b.Run(fmt.Sprintf("benchmark_%d", count), func(bb *testing.B) {
for j := 0; j < bb.N; j++ {
if err := chiv.ArchiveRowsWithContext(ctx, rows, uploader, bucket, format); err != nil {
bb.Error(err)
}
rows.ndx = 0
}
})
}
}
type benchmarkRows struct {
columnTypes []*sql.ColumnType
column sql.RawBytes
ndx, max int
}
func (r *benchmarkRows) ColumnTypes() ([]*sql.ColumnType, error) {
return r.columnTypes, nil
}
func (r *benchmarkRows) Next() bool {
return r.ndx < r.max
}
func (r *benchmarkRows) Scan(c ...interface{}) error {
for i := range c {
*(c[i].(*sql.RawBytes)) = r.column
}
r.ndx++
return nil
}
func (r *benchmarkRows) Err() error {
return nil
}
type benchmarkFormatter struct{}
func (_ *benchmarkFormatter) Open() error {
return nil
}
func (_ *benchmarkFormatter) Format(record [][]byte) error {
return nil
}
func (_ *benchmarkFormatter) Close() error {
return nil
}