-
Notifications
You must be signed in to change notification settings - Fork 7
/
benchmarks_test.go
150 lines (109 loc) · 3.39 KB
/
benchmarks_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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package namedParameterQuery
import (
"testing"
"bytes"
"fmt"
)
func BenchmarkSimpleParsing(bench *testing.B) {
query := "SELECT [foo] FROM bar WHERE [baz] = :quux"
for i := 0; i < bench.N; i++ {
NewNamedParameterQuery(query)
}
}
func BenchmarkMultiOccurrenceParsing(bench *testing.B) {
query := "SELECT [foo] FROM bar WHERE [baz] = :quux " +
"AND [something] = :quux " +
"OR [otherStuff] NOT :quux"
for i := 0; i < bench.N; i++ {
NewNamedParameterQuery(query)
}
}
func BenchmarkMultiParameterParsing(bench *testing.B) {
query := "SELECT [foo] FROM bar WHERE [baz] = :quux " +
"AND [something] = :quux2 " +
"OR [otherStuff] NOT :quux3"
for i := 0; i < bench.N; i++ {
NewNamedParameterQuery(query)
}
}
/*
Benchmarks returning a query which has no parameters
*/
func BenchmarkNoReplacement(bench *testing.B) {
query := "SELECT [foo] FROM bar WHERE [baz] = quux"
replacer := NewNamedParameterQuery(query)
for i := 0; i < bench.N; i++ {
replacer.GetParsedParameters()
}
}
/*
Benchmarks returning a query which uses exactly one parameter
*/
func BenchmarkSingleReplacement(bench *testing.B) {
query := "SELECT [foo] FROM bar WHERE [baz] = :quux"
replacer := NewNamedParameterQuery(query)
for i := 0; i < bench.N; i++ {
replacer.SetValue("quux", bench.N)
replacer.GetParsedParameters()
}
}
/*
Benchmarks returning a query which has multiple occurrences of one parameter
*/
func BenchmarkMultiOccurrenceReplacement(bench *testing.B) {
query := "SELECT [foo] FROM bar WHERE [baz] = :quux " +
"AND [something] = :quux " +
"OR [otherStuff] NOT :quux"
replacer := NewNamedParameterQuery(query)
for i := 0; i < bench.N; i++ {
replacer.SetValue("quux", bench.N)
replacer.GetParsedParameters()
}
}
/*
Benchmarks returning a query which has multiple parameters
*/
func BenchmarkMultiParameterReplacement(bench *testing.B) {
query := "SELECT [foo] FROM bar WHERE [baz] = :quux " +
"AND [something] = :quux2 " +
"OR [otherStuff] NOT :quux3 "
replacer := NewNamedParameterQuery(query)
for i := 0; i < bench.N; i++ {
replacer.SetValue("quux", bench.N)
replacer.SetValue("quux2", bench.N)
replacer.SetValue("quux3", bench.N)
replacer.GetParsedParameters()
}
}
func Benchmark16ParameterReplacement(bench *testing.B) {
benchmarkMultiParameter(bench, 16)
}
func Benchmark32ParameterReplacement(bench *testing.B) {
benchmarkMultiParameter(bench, 32)
}
func Benchmark64ParameterReplacement(bench *testing.B) {
benchmarkMultiParameter(bench, 64)
}
func Benchmark128ParameterReplacement(bench *testing.B) {
benchmarkMultiParameter(bench, 128)
}
/*
Benchmarks returning a query which has multiple parameters
*/
func benchmarkMultiParameter(bench *testing.B, parameterCount int) {
var queryBuffer bytes.Buffer
var parameterName string
queryBuffer.WriteString("SELECT [foo] FROM bar WHERE [baz] = :quux ")
queryLine := "AND [something] = :quux%d "
for i := 0; i < parameterCount; i++ {
queryBuffer.WriteString(fmt.Sprintf(queryLine, i))
}
replacer := NewNamedParameterQuery(queryBuffer.String())
for i := 0; i < bench.N; i++ {
for n := 0; n < parameterCount; n++ {
parameterName = fmt.Sprintf("quux%d", n)
replacer.SetValue(parameterName, bench.N)
}
replacer.GetParsedParameters()
}
}