-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchconn_test.go
110 lines (100 loc) · 2.29 KB
/
chconn_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 gotests_test
import (
"context"
"testing"
"github.com/vahid-sohrabloo/chconn"
"github.com/vahid-sohrabloo/chconn/column"
)
func BenchmarkTestChconnSelect100MUint64(b *testing.B) {
// return
ctx := context.Background()
c, err := chconn.Connect(ctx, "password=salam")
if err != nil {
b.Fatal(err)
}
// var datStr [][]byte
colRead := column.NewUint64(false)
for n := 0; n < b.N; n++ {
s, err := c.Select(ctx, "SELECT number FROM system.numbers_mt LIMIT 100000000")
if err != nil {
b.Fatal(err)
}
// colReadStr := column.NewString(false)
for s.Next() {
if err := s.NextColumn(colRead); err != nil {
b.Fatal(err)
}
colRead.GetAllUnsafe()
// if err := s.NextColumn(colReadStr); err != nil {
// b.Fatal(err)
// }
// datStr = datStr[:0]
// colReadStr.ReadAll(&datStr)
}
if err := s.Err(); err != nil {
b.Fatal(err)
}
s.Close()
}
}
func BenchmarkTestChconnSelect1MString(b *testing.B) {
// return
ctx := context.Background()
c, err := chconn.Connect(ctx, "password=salam")
if err != nil {
b.Fatal(err)
}
// var datStr [][]byte
colRead := column.NewString(false)
var data [][]byte
for n := 0; n < b.N; n++ {
s, err := c.Select(ctx, "SELECT randomString(20) FROM system.numbers_mt LIMIT 1000000")
if err != nil {
b.Fatal(err)
}
for s.Next() {
data = data[:0]
if err := s.NextColumn(colRead); err != nil {
b.Fatal(err)
}
colRead.ReadAll(&data)
}
if err := s.Err(); err != nil {
b.Fatal(err)
}
s.Close()
}
}
func BenchmarkTestChconnInsert10M(b *testing.B) {
// return
ctx := context.Background()
c, err := chconn.Connect(ctx, "password=salam")
if err != nil {
b.Fatal(err)
}
_, err = c.Exec(ctx, "DROP TABLE IF EXISTS test_insert_chconn")
if err != nil {
b.Fatal(err)
}
_, err = c.Exec(ctx, "CREATE TABLE test_insert_chconn (id UInt64,v String) ENGINE = Null")
if err != nil {
b.Fatal(err)
}
const (
rowsInBlock = 10_000_000
)
idColumns := column.NewUint64(false)
vColumns := column.NewString(false)
for n := 0; n < b.N; n++ {
idColumns.Reset()
vColumns.Reset()
for y := 0; y < rowsInBlock; y++ {
idColumns.Append(1)
vColumns.Append([]byte("test"))
}
err := c.Insert(ctx, "INSERT INTO test_insert_chconn VALUES", idColumns, vColumns)
if err != nil {
b.Fatal(err)
}
}
}