-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathsql_builder_benchmark_test.go
97 lines (84 loc) · 1.86 KB
/
sql_builder_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
package db_sql_benchmark
import (
"testing"
_ "github.com/go-sql-driver/mysql"
"github.com/gocraft/dbr"
"github.com/lann/squirrel"
)
//
// Build, but don't execute, queries
//
//
// dbr
//
func BenchmarkDbrBuilderSimple(b *testing.B) {
sess := dbrSess()
b.ResetTimer()
for n := 0; n < b.N; n++ {
sess.Select("id").From("tickets").Where("subdomain_id = ? and (state = ? or state = ?)", 1, "open", "spam").ToSql()
}
}
func BenchmarkDbrBuilderComplex(b *testing.B) {
sess := dbrSess()
arg_eq1 := dbr.Eq{"f": 2, "x": "hi"}
arg_eq2 := map[string]interface{}{"g": 3}
arg_eq3 := dbr.Eq{"h": []int{1, 2, 3}}
b.ResetTimer()
for n := 0; n < b.N; n++ {
sess.Select("a", "b", "z", "y", "x").
Distinct().
From("c").
Where("d = ? OR e = ?", 1, "wat").
Where(arg_eq1).
Where(arg_eq2).
Where(arg_eq3).
GroupBy("i").
GroupBy("ii").
GroupBy("iii").
Having("j = k").
Having("jj = ?", 1).
Having("jjj = ?", 2).
OrderBy("l").
OrderBy("l").
OrderBy("l").
Limit(7).
Offset(8).
ToSql()
}
}
//
// Squirrel
//
func BenchmarkSquirrelBuilderSimple(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
squirrel.Select("id").From("tickets").Where("subdomain_id = ? and (state = ? or state = ?)", 1, "open", "spam").ToSql()
}
}
func BenchmarkSquirrelBuilderComplex(b *testing.B) {
arg_eq1 := squirrel.Eq{"f": 2, "x": "hi"}
arg_eq2 := map[string]interface{}{"g": 3}
arg_eq3 := squirrel.Eq{"h": []int{1, 2, 3}}
b.ResetTimer()
for n := 0; n < b.N; n++ {
squirrel.Select("a", "b", "z", "y", "x").
Distinct().
From("c").
Where("d = ? OR e = ?", 1, "wat").
Where(arg_eq1).
Where(arg_eq2).
Where(arg_eq3).
GroupBy("i").
GroupBy("ii").
GroupBy("iii").
Having("j = k").
Having("jj = ?", 1).
Having("jjj = ?", 2).
OrderBy("l").
OrderBy("l").
OrderBy("l").
Limit(7).
Offset(8).
ToSql()
}
}