-
Notifications
You must be signed in to change notification settings - Fork 15
/
goqu_benchmark_test.go
105 lines (95 loc) · 1.77 KB
/
goqu_benchmark_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
package db_sql_benchmark
import (
"database/sql"
"testing"
"github.com/DATA-DOG/go-sqlmock"
"github.com/doug-martin/goqu"
_ "github.com/go-sql-driver/mysql"
)
var driver *sql.DB
func init() {
db, _ := sqlmock.New()
driver = db
}
//
// Select benchmarks
//
func BenchmarkGoquSelectSimple(b *testing.B) {
db := goqu.New("default", driver)
b.ResetTimer()
for n := 0; n < b.N; n++ {
db.From("tickets").
Where(
goqu.And(
goqu.I("subdomain_id").Eq(1),
goqu.Or(
goqu.I("state").Eq("open"),
goqu.I("state").Eq("spam"),
),
),
).
ToSql()
}
}
func BenchmarkGoquSelectConditional(b *testing.B) {
db := goqu.New("default", driver)
b.ResetTimer()
for n := 0; n < b.N; n++ {
qb := db.From("tickets").
Where(
goqu.And(
goqu.I("subdomain_id").Eq(1),
goqu.Or(
goqu.I("state").Eq("open"),
goqu.I("state").Eq("spam"),
),
),
)
if n%2 == 0 {
qb.GroupBy("subdomain_id").
Having(goqu.I("number").Eq(1)).
Order(goqu.I("state").Asc()).
Limit(7).
Offset(8)
}
qb.ToSql()
}
}
func BenchmarkGoquSelectComplex(b *testing.B) {
db := goqu.New("default", driver)
b.ResetTimer()
for n := 0; n < b.N; n++ {
db.From("a", "b", "z", "y").
Select(goqu.DISTINCT("x")).
Where(
goqu.Or(
goqu.I("d").Eq(1),
goqu.I("e").Eq("wat"),
)).
Where(
goqu.And(
goqu.I("f").Eq(2),
goqu.I("x").Eq("hi"),
)).
Where(
goqu.And(
goqu.I("g").Eq(3),
)).
Where(
goqu.And(
goqu.I("h").Eq([]int{1, 2, 3}),
)).
GroupBy("i").
GroupBy("ii").
GroupBy("iii").
Having(goqu.I("j = k")).
Having(goqu.I("jj").Eq(1)).
Having(goqu.I("jjj").Eq(2)).
Order(goqu.I("l").Asc()).
Order(goqu.I("l").Asc()).
Order(goqu.I("l").Asc()).
Limit(7).
Offset(8).
ToSql()
}
}