forked from nakagami/firebirdsql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
decode_speed_test.go
75 lines (67 loc) · 1.23 KB
/
decode_speed_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
package firebirdsql
import (
"database/sql"
"log"
"testing"
)
func BenchmarkRead(b *testing.B) {
b.StopTimer()
temppath := TempFileName("test_basic_")
conn, err := sql.Open("firebirdsql_createdb", "sysdba:masterkey@localhost:3050"+temppath)
query := `
CREATE TABLE PERFTEST (
A SMALLINT,
B INT,
C BIGINT,
D VARCHAR(255),
B1 INT,
B2 INT,
B3 INT,
B4 INT,
B5 INT,
B6 INT,
B7 INT,
B8 INT,
B9 INT,
B11 INT,
B12 INT,
B13 INT,
B14 INT,
B15 INT,
B16 INT,
B17 INT,
B18 INT,
B19 INT
);
`
_, err = conn.Exec(query)
if err != nil {
b.Error(err)
log.Fatal(err)
}
tx, err := conn.Begin()
if err != nil {
b.Error(err)
}
stmt, err := tx.Prepare("INSERT INTO PERFTEST (A,B,C,D,B1,B2,B3,B4,B5,B6,B7,B8,B9,B11,B12,B13,B14,B15,B16,B17,B18,B19) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
if err != nil {
b.Error(err)
log.Fatal(err)
}
for i := 0; i < b.N; i++ {
stmt.Exec(i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i)
}
tx.Commit()
b.StartTimer()
for i := 0; i < b.N; i++ {
rows, err := conn.Query("SELECT * FROM PERFTEST")
if err != nil {
b.Error(err)
}
var vals []interface{}
for rows.Next() {
rows.Scan(vals...)
}
rows.Close()
}
}