Skip to content

Commit fbcab60

Browse files
committed
Add more benchmarks
1 parent 976bf0f commit fbcab60

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

expr_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,48 @@ func Benchmark_expr(b *testing.B) {
3535
}
3636
}
3737

38+
func Benchmark_filter(b *testing.B) {
39+
params := make(map[string]interface{})
40+
params["max"] = 50
41+
42+
program, err := expr.Compile(`filter(1..100, {# > max})`, expr.Env(params))
43+
if err != nil {
44+
b.Fatal(err)
45+
}
46+
47+
for n := 0; n < b.N; n++ {
48+
_, err = vm.Run(program, params)
49+
}
50+
51+
if err != nil {
52+
b.Fatal(err)
53+
}
54+
}
55+
56+
func Benchmark_access(b *testing.B) {
57+
type Price struct {
58+
Value int64
59+
}
60+
type Env struct {
61+
Price Price
62+
}
63+
64+
program, err := expr.Compile(`Price.Value > 0`, expr.Env(Env{}))
65+
if err != nil {
66+
b.Fatal(err)
67+
}
68+
69+
env := Env{Price: Price{Value: 1}}
70+
71+
for n := 0; n < b.N; n++ {
72+
_, err = vm.Run(program, env)
73+
}
74+
75+
if err != nil {
76+
b.Fatal(err)
77+
}
78+
}
79+
3880
func ExampleEval() {
3981
output, err := expr.Eval("'hello world'", nil)
4082
if err != nil {

0 commit comments

Comments
 (0)