-
Notifications
You must be signed in to change notification settings - Fork 42
/
bench_test.go
110 lines (101 loc) · 1.97 KB
/
bench_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
package rql
import (
"database/sql"
"testing"
"time"
)
type Int int
type Date time.Time
type T struct {
Age int `rql:"filter,sort"`
Name string `rql:"filter,sort"`
Address struct {
Name string `rql:"filter,sort"`
}
Admin bool `rql:"filter"`
CreatedAt time.Time `rql:"filter,sort"`
Int Int `rql:"filter"`
NullInt sql.NullInt64 `rql:"filter"`
Date *Date `rql:"filter"`
Bool bool `rql:"filter"`
PtrBool *bool `rql:"filter"`
Work *struct {
Name string `rql:"filter"`
Address *struct {
PtrString *string `rql:"filter"`
}
}
}
var p = MustNewParser(Config{
Model: T{},
FieldSep: ".",
})
func BenchmarkLargeQuery(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err := p.Parse([]byte(`{
"filter": {
"admin": true,
"name": "foo",
"address.name": "bar",
"$or": [
{ "age": { "$gte": 20 } },
{ "age": { "$lte": 10 } },
{ "name": { "$like": "foo" } },
{ "work.name": { "$like": "bar" } },
{ "work.address.ptr_string": { "$like": "baz" } }
],
"created_at": "2018-05-10T05:03:31.031Z",
"int": 10,
"null_int": 10,
"date": "2018-05-10T05:03:31.031Z",
"bool": true,
"ptr_bool": false
},
"sort": [
"address.name",
"-age"
],
"offset": 100,
"limit": 10
}`))
if err != nil {
b.Error(err)
}
}
}
func BenchmarkMediumQuery(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err := p.Parse([]byte(`{
"filter": {
"name": "foo",
"address.name": "bar",
"$or": [
{ "age": { "$gt": 20 } },
{ "age": { "$lt": 10 } }
],
"created_at": "2018-05-10T05:03:31.031Z"
},
"sort": [ "address.name" ],
"offset": 100,
"limit": 10
}`))
if err != nil {
b.Error(err)
}
}
}
func BenchmarkSmallQuery(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err := p.Parse([]byte(`{
"filter": {
"address.name": "TLV",
"admin": true
},
"offset": 25,
"limit": 10
}`))
if err != nil {
b.Error(err)
}
}
}