-
Notifications
You must be signed in to change notification settings - Fork 2
/
benchmarks_test.go
176 lines (136 loc) · 4.41 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
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
package ksql
import (
"testing"
)
func BenchmarkLexingNumPlusNum(b *testing.B) {
benchLexing(b, "1 + 1")
}
func BenchmarkLexingIdentNum(b *testing.B) {
benchLexing(b, ".field1 + 1")
}
func BenchmarkLexingIdentIdent(b *testing.B) {
benchLexing(b, ".field1 + .field2")
}
func BenchmarkLexingFNameLName(b *testing.B) {
benchLexing(b, `.first_name + " " + .last_name`)
}
func BenchmarkLexingParenDiv(b *testing.B) {
benchLexing(b, `(1 + 1) / 2`)
}
func BenchmarkLexingParenDivIdents(b *testing.B) {
benchLexing(b, `(.field1 + .field2) / .field3`)
}
func BenchmarkLexingCompanyEmployees(b *testing.B) {
benchLexing(b, `.properties.employees > 20`)
}
func BenchmarkLexingParenNot(b *testing.B) {
benchLexing(b, `!(.f1 != .f2)`)
}
func BenchmarkLexingCoerceDateTimeSelector(b *testing.B) {
benchLexing(b, `COERCE .dt1 _datetime_ == COERCE .dt2 _datetime_`)
}
func BenchmarkLexingCoerceDateTimeSelectorMixed(b *testing.B) {
benchLexing(b, `COERCE .dt1 _datetime_ == COERCE "2022-01-02" _datetime_`)
}
func BenchmarkLexingCoerceDateTimeSelectorConstant(b *testing.B) {
benchLexing(b, `COERCE "2022-01-02" _datetime_ == COERCE "2022-01-02" _datetime_`)
}
func BenchmarkParsingNumPlusNum(b *testing.B) {
benchParsing(b, "1 + 1")
}
func BenchmarkParsingIdentNum(b *testing.B) {
benchParsing(b, ".field1 + 1")
}
func BenchmarkParsingIdentIdent(b *testing.B) {
benchParsing(b, ".field1 + .field2")
}
func BenchmarkParsingFNameLName(b *testing.B) {
benchParsing(b, `.first_name + " " + .last_name`)
}
func BenchmarkParsingParenDiv(b *testing.B) {
benchParsing(b, `(1 + 1) / 2`)
}
func BenchmarkParsingParenDivIdents(b *testing.B) {
benchParsing(b, `(.field1 + .field2) / .field3`)
}
func BenchmarkParsingCompanyEmployees(b *testing.B) {
benchParsing(b, `.properties.employees > 20`)
}
func BenchmarkParsingParenNot(b *testing.B) {
benchParsing(b, `!(.f1 != .f2)`)
}
func BenchmarkParsingCoerceDateTimeSelector(b *testing.B) {
benchParsing(b, `COERCE .dt1 _datetime_ == COERCE .dt2 _datetime_`)
}
func BenchmarkParsingCoerceDateTimeSelectorMixed(b *testing.B) {
benchParsing(b, `COERCE .dt1 _datetime_ == COERCE "2022-01-02" _datetime_`)
}
func BenchmarkParsingCoerceDateTimeSelectorConstant(b *testing.B) {
benchParsing(b, `COERCE "2022-01-02" _datetime_ == COERCE "2022-01-02" _datetime_`)
}
func BenchmarkExecutionNumPlusNum(b *testing.B) {
benchExecution(b, "1 + 1 + 1 + 1 + 1", ``)
}
func BenchmarkExecutionIdentNum(b *testing.B) {
benchExecution(b, ".field1 + 1", `{"field1":1}`)
}
func BenchmarkExecutionIdentIdent(b *testing.B) {
benchExecution(b, ".field1 + .field2", `{"field1":1,"field2":1}`)
}
func BenchmarkExecutionFNameLName(b *testing.B) {
benchExecution(b, `.first_name + " " + .last_name`, `{"first_name":"Joey","last_name":"Bloggs"}`)
}
func BenchmarkExecutionParenDiv(b *testing.B) {
benchExecution(b, `(1 + 1) / 2`, ``)
}
func BenchmarkExecutionParenDivIdents(b *testing.B) {
benchExecution(b, `(.field1 + .field2) / .field3`, `{"field1":1,"field2":1,"field3":2}`)
}
func BenchmarkExecutionCompanyEmployees(b *testing.B) {
benchExecution(b, `.properties.employees > 20`, `{"name":"Company","properties":{"employees":50}}`)
}
func BenchmarkExecutionParenNot(b *testing.B) {
benchExecution(b, `!(.f1 != .f2)`, `{"f1":true,"f2":false}`)
}
func BenchmarkExecutionCoerceDateTimeSelector(b *testing.B) {
benchExecution(b, `COERCE .dt1 _datetime_ == COERCE .dt2 _datetime_`, `{"dt1":"2022-01-02","dt2":"2022-01-02"}`)
}
func BenchmarkExecutionCoerceDateTimeSelectorMixed(b *testing.B) {
benchExecution(b, `COERCE .dt1 _datetime_ == COERCE "2022-01-02" _datetime_`, `{"dt1":"2022-01-02"}`)
}
func BenchmarkExecutionCoerceDateTimeSelectorConstant(b *testing.B) {
benchExecution(b, `COERCE "2022-01-02" _datetime_ == COERCE "2022-01-02" _datetime_`, ``)
}
func benchExecution(b *testing.B, expression, input string) {
ex, err := Parse([]byte(expression))
if err != nil {
b.Fatal(err)
}
in := []byte(input)
b.SetBytes(int64(len(in)))
for i := 0; i < b.N; i++ {
_, err := ex.Calculate(in)
if err != nil {
b.Fatal(err)
}
}
}
func benchParsing(b *testing.B, expression string) {
b.SetBytes(int64(len(expression)))
for i := 0; i < b.N; i++ {
_, err := Parse([]byte(expression))
if err != nil {
b.Fatal(err)
}
}
}
func benchLexing(b *testing.B, expression string) {
exp := []byte(expression)
b.SetBytes(int64(len(expression)))
for i := 0; i < b.N; i++ {
_, err := collect(exp)
if err != nil {
b.Fatal(err)
}
}
}