-
Notifications
You must be signed in to change notification settings - Fork 3
/
builq_bench_test.go
91 lines (81 loc) · 1.85 KB
/
builq_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
package builq_test
import (
"testing"
"github.com/cristalhq/builq"
)
func BenchmarkBuildSimple(b *testing.B) {
for i := 0; i < b.N; i++ {
q := builq.New()
q("SELECT %s FROM %s", "foo,bar", "table")
q("WHERE id = %$", 123)
query, args, err := q.Build()
switch {
case err != nil:
b.Fatal(err)
case query == "":
b.Fatal("empty query")
case len(args) == 0:
b.Fatal("empty args")
}
}
}
func BenchmarkBuildManyArgs(b *testing.B) {
for i := 0; i < b.N; i++ {
q := builq.New()
q("SELECT %s FROM %s", "foo,bar", "table")
q("WHERE id = %$", 123)
q("AND user_id = %$ OR referral_id = %$", 123, 456)
q("OR status = %$ OR name = %$", "admin", "nice")
q("AND password LIKE %$ OR password = %$", "str0ng", "qwerty")
q("GROUP BY %$", "foo")
q("ORDER BY %$", "bar")
q("LIMIT %$;", 123)
query, args, err := q.Build()
switch {
case err != nil:
b.Fatal(err)
case query == "":
b.Fatal("empty query")
case len(args) == 0:
b.Fatal("empty args")
}
}
}
func BenchmarkBuildCached(b *testing.B) {
q := builq.New()
q("SELECT %s FROM %s", "foo,bar", "table")
q("WHERE id = %$", 123)
q("AND user_id = %$ OR referral_id = %$", 123, 456)
q("OR status = %$ OR name = %$", "admin", "nice")
q("GROUP BY %$", "foo")
q("ORDER BY %$", "bar")
q("LIMIT %$;", 123)
query, args, err := q.Build()
b.ResetTimer()
for i := 0; i < b.N; i++ {
switch {
case err != nil:
b.Fatal(err)
case query == "":
b.Fatal("empty query")
case len(args) == 0:
b.Fatal("empty args")
}
}
}
func BenchmarkBuilder(b *testing.B) {
for i := 0; i < b.N; i++ {
var bb builq.Builder
bb.Addf("SELECT %s FROM %s", "foo,bar", "table")
bb.Addf("WHERE id = %$", 123)
query, args, err := bb.Build()
switch {
case err != nil:
b.Fatal(err)
case query == "":
b.Fatal("empty query")
case len(args) == 0:
b.Fatal("empty args")
}
}
}