forked from jwilm0028/go-driver-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uptrace_test.go
97 lines (87 loc) · 1.86 KB
/
uptrace_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
package gotests
import (
"context"
"testing"
"time"
"github.com/uptrace/go-clickhouse/ch"
)
func BenchmarkTestUptraceSelect100MUint64(b *testing.B) {
db := ch.Connect(
ch.WithCompression(false),
ch.WithTimeout(time.Second*30),
)
err := db.Ping(context.Background())
if err != nil {
panic(err)
}
for n := 0; n < b.N; n++ {
rows, err := db.QueryContext(context.Background(), "SELECT number FROM system.numbers_mt LIMIT 100000000")
if err != nil {
b.Fatal(err)
}
for rows.Next() {
var value uint64
if err := rows.Scan(&value); err != nil {
b.Fatal(err)
}
}
}
}
func BenchmarkTestUptraceSelect10MString(b *testing.B) {
db := ch.Connect(
ch.WithCompression(false),
ch.WithTimeout(time.Second*30),
)
err := db.Ping(context.Background())
if err != nil {
panic(err)
}
for n := 0; n < b.N; n++ {
rows, err := db.QueryContext(context.Background(), "SELECT toString(number) FROM system.numbers_mt LIMIT 10000000")
if err != nil {
b.Fatal(err)
}
for rows.Next() {
var value string
if err := rows.Scan(&value); err != nil {
b.Fatal(err)
}
}
}
}
type Model struct {
ch.CHModel `ch:",columnar,engine:Null()"`
Col1 []uint64
Col2 []string
}
func BenchmarkTestUptraceInsert10M(b *testing.B) {
db := ch.Connect(
ch.WithCompression(false),
ch.WithTimeout(time.Second*30),
)
ctx := context.Background()
err := db.Ping(ctx)
if err != nil {
panic(err)
}
if err := db.ResetModel(ctx, (*Model)(nil)); err != nil {
panic(err)
}
const (
rowsInBlock = 10_000_000
)
for n := 0; n < b.N; n++ {
model := Model{
Col1: make([]uint64, 0, rowsInBlock),
Col2: make([]string, 0, rowsInBlock),
}
for i := 0; i < rowsInBlock; i++ {
model.Col1 = append(model.Col1, uint64(i))
model.Col2 = append(model.Col2, "test")
}
_, err := db.NewInsert().Model(&model).Exec(ctx)
if err != nil {
panic(err)
}
}
}