forked from pganalyze/pg_query_go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_test.go
185 lines (156 loc) · 5.25 KB
/
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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package pg_query_test
import (
"testing"
"github.com/lfittl/pg_query_go"
)
// Prevent compiler optimizations by assigning all results to global variables
var err error
var resultStr string
var resultTree pg_query.ParsetreeList
func benchmarkParse(input string, b *testing.B) {
for i := 0; i < b.N; i++ {
resultTree, err = pg_query.Parse(input)
if err != nil {
b.Errorf("Benchmark produced error %s\n\n", err)
}
if len(resultTree.Statements) == 0 {
b.Errorf("Benchmark produced empty result\n\n")
}
}
}
func benchmarkParseParallel(input string, b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
var tree pg_query.ParsetreeList
for pb.Next() {
tree, err = pg_query.Parse(input)
if err != nil {
b.Errorf("Benchmark produced error %s\n\n", err)
}
if len(tree.Statements) == 0 {
b.Errorf("Benchmark produced empty result\n\n")
}
}
})
}
func benchmarkRawParse(input string, b *testing.B) {
for i := 0; i < b.N; i++ {
resultStr, err = pg_query.ParseToJSON(input)
if err != nil {
b.Errorf("Benchmark produced error %s\n\n", err)
}
if resultStr == "" {
b.Errorf("Benchmark produced empty result\n\n")
}
}
}
func benchmarkRawParseParallel(input string, b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
var str string
for pb.Next() {
str, err = pg_query.ParseToJSON(input)
if err != nil {
b.Errorf("Benchmark produced error %s\n\n", err)
}
if str == "" {
b.Errorf("Benchmark produced empty result\n\n")
}
}
})
}
func benchmarkFingerprint(input string, b *testing.B) {
for i := 0; i < b.N; i++ {
resultTree, err = pg_query.Parse(input)
if err != nil {
b.Errorf("Benchmark produced error %s\n\n", err)
}
resultStr = resultTree.Fingerprint()
if resultStr == "" {
b.Errorf("Benchmark produced empty result\n\n")
}
}
}
func benchmarkFastFingerprint(input string, b *testing.B) {
for i := 0; i < b.N; i++ {
resultStr, err = pg_query.FastFingerprint(input)
if err != nil {
b.Errorf("Benchmark produced error %s\n\n", err)
}
if resultStr == "" {
b.Errorf("Benchmark produced empty result\n\n")
}
}
}
func benchmarkNormalize(input string, b *testing.B) {
for i := 0; i < b.N; i++ {
resultStr, err := pg_query.Normalize(input)
if err != nil {
b.Errorf("Benchmark produced error %s\n\n", err)
}
if resultStr == "" {
b.Errorf("Benchmark produced empty result\n\n")
}
}
}
func BenchmarkParseSelect1(b *testing.B) {
benchmarkParse("SELECT 1", b)
}
func BenchmarkParseSelect2(b *testing.B) {
benchmarkParse("SELECT 1 FROM x WHERE y IN ('a', 'b', 'c')", b)
}
func BenchmarkParseCreateTable(b *testing.B) {
benchmarkParse("CREATE TABLE types (a float(2), b float(49), c NUMERIC(2, 3), d character(4), e char(5), f varchar(6), g character varying(7))", b)
}
func BenchmarkParseSelect1Parallel(b *testing.B) {
benchmarkParseParallel("SELECT 1", b)
}
func BenchmarkParseSelect2Parallel(b *testing.B) {
benchmarkParseParallel("SELECT 1 FROM x WHERE y IN ('a', 'b', 'c')", b)
}
func BenchmarkParseCreateTableParallel(b *testing.B) {
benchmarkParseParallel("CREATE TABLE types (a float(2), b float(49), c NUMERIC(2, 3), d character(4), e char(5), f varchar(6), g character varying(7))", b)
}
func BenchmarkRawParseSelect1(b *testing.B) {
benchmarkRawParse("SELECT 1", b)
}
func BenchmarkRawParseSelect2(b *testing.B) {
benchmarkRawParse("SELECT 1 FROM x WHERE y IN ('a', 'b', 'c')", b)
}
func BenchmarkRawParseCreateTable(b *testing.B) {
benchmarkRawParse("CREATE TABLE types (a float(2), b float(49), c NUMERIC(2, 3), d character(4), e char(5), f varchar(6), g character varying(7))", b)
}
func BenchmarkRawParseSelect1Parallel(b *testing.B) {
benchmarkRawParseParallel("SELECT 1", b)
}
func BenchmarkRawParseSelect2Parallel(b *testing.B) {
benchmarkRawParseParallel("SELECT 1 FROM x WHERE y IN ('a', 'b', 'c')", b)
}
func BenchmarkRawParseCreateTableParallel(b *testing.B) {
benchmarkRawParseParallel("CREATE TABLE types (a float(2), b float(49), c NUMERIC(2, 3), d character(4), e char(5), f varchar(6), g character varying(7))", b)
}
func BenchmarkFingerprintSelect1(b *testing.B) {
benchmarkFingerprint("SELECT 1", b)
}
func BenchmarkFingerprintSelect2(b *testing.B) {
benchmarkFingerprint("SELECT 1 FROM x WHERE y IN ('a', 'b', 'c')", b)
}
func BenchmarkFingerprintCreateTable(b *testing.B) {
benchmarkFingerprint("CREATE TABLE types (a float(2), b float(49), c NUMERIC(2, 3), d character(4), e char(5), f varchar(6), g character varying(7))", b)
}
func BenchmarkFastFingerprintSelect1(b *testing.B) {
benchmarkFastFingerprint("SELECT 1", b)
}
func BenchmarkFastFingerprintSelect2(b *testing.B) {
benchmarkFastFingerprint("SELECT 1 FROM x WHERE y IN ('a', 'b', 'c')", b)
}
func BenchmarkFastFingerprintCreateTable(b *testing.B) {
benchmarkFastFingerprint("CREATE TABLE types (a float(2), b float(49), c NUMERIC(2, 3), d character(4), e char(5), f varchar(6), g character varying(7))", b)
}
func BenchmarkNormalizeSelect1(b *testing.B) {
benchmarkNormalize("SELECT 1", b)
}
func BenchmarkNormalizeSelect2(b *testing.B) {
benchmarkNormalize("SELECT 1 FROM x WHERE y IN ('a', 'b', 'c')", b)
}
func BenchmarkNormalizeCreateTable(b *testing.B) {
benchmarkNormalize("CREATE TABLE types (a float(2), b float(49), c NUMERIC(2, 3), d character(4), e char(5), f varchar(6), g character varying(7))", b)
}