-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpr_test.go
49 lines (44 loc) · 833 Bytes
/
expr_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
package expr
import (
"github.com/antlr/antlr4/runtime/Go/antlr"
"reflect"
"testing"
)
func parse(withCache bool) bool {
input := `(3+2)*2 >= 1`
//input = `'s' in ('a')`
parser := NewParser()
var tree antlr.Tree
var err error
if withCache {
tree, err = parser.ParseWithCache(input)
} else {
tree, err = parser.Parse(input)
}
if err != nil {
panic(err)
}
evaluator, _ := NewEvaluatorWithParser(tree, parser, nil)
result, err := evaluator.Evaluate()
if err != nil {
panic(err)
}
return result
}
func BenchmarkEvaluator(b *testing.B) {
for i := 0; i < b.N; i++ {
parse(false)
}
}
func BenchmarkEvaluateWithCache(b *testing.B) {
for i := 0; i < b.N; i++ {
parse(true)
}
}
func BenchmarkReflectValue(b *testing.B) {
a := 1
for i := 0; i < b.N; i++ {
va := reflect.ValueOf(a)
_ = va.Int()
}
}