-
Notifications
You must be signed in to change notification settings - Fork 27
/
bench_test.go
99 lines (88 loc) · 2.47 KB
/
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
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
package proxy
import (
"context"
"database/sql/driver"
"testing"
)
type nullConn struct{}
func (nullConn) Prepare(query string) (driver.Stmt, error) { return nil, nil }
func (nullConn) Close() error { return nil }
func (nullConn) Begin() (driver.Tx, error) { return nil, nil }
func (nullConn) Exec(query string, args []driver.Value) (driver.Result, error) { return nil, nil }
type nullConnCtx struct{}
func (nullConnCtx) Prepare(query string) (driver.Stmt, error) { return nil, nil }
func (nullConnCtx) Close() error { return nil }
func (nullConnCtx) Begin() (driver.Tx, error) { return nil, nil }
func (nullConnCtx) Exec(query string, args []driver.Value) (driver.Result, error) { return nil, nil }
func (nullConnCtx) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) {
return nil, nil
}
type nullLogger struct{}
func (nullLogger) Output(calldepth int, s string) error { return nil }
func BenchmarkDirectly(b *testing.B) {
conn := nullConn{}
args := []driver.Value{int64(123456789)}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
conn.Exec("CREATE TABLE t1 (id INTEGER PRIMARY KEY)", args)
}
}
func BenchmarkNilHook(b *testing.B) {
ctx := context.Background()
conn := &Conn{
Conn: nullConn{},
Proxy: &Proxy{},
}
args := []driver.NamedValue{
{
Ordinal: 1,
Value: int64(123456789),
},
}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
conn.ExecContext(ctx, "CREATE TABLE t1 (id INTEGER PRIMARY KEY)", args)
}
}
func BenchmarkNilHookCtx(b *testing.B) {
ctx := context.Background()
conn := &Conn{
Conn: nullConnCtx{},
Proxy: &Proxy{},
}
args := []driver.NamedValue{
{
Ordinal: 1,
Value: int64(123456789),
},
}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
conn.ExecContext(ctx, "CREATE TABLE t1 (id INTEGER PRIMARY KEY)", args)
}
}
func BenchmarkTracer(b *testing.B) {
ctx := context.Background()
conn := &Conn{
Conn: nullConnCtx{},
Proxy: &Proxy{
hooks: NewTraceHooks(TracerOptions{
Outputter: nullLogger{},
}),
},
}
args := []driver.NamedValue{
{
Ordinal: 1,
Value: int64(123456789),
},
}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
conn.ExecContext(ctx, "CREATE TABLE t1 (id INTEGER PRIMARY KEY)", args)
}
}