forked from open-policy-agent/opa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrego_bench_test.go
70 lines (59 loc) · 1.43 KB
/
rego_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
package rego
import (
"context"
"fmt"
"testing"
"github.com/open-policy-agent/opa/ast"
"github.com/open-policy-agent/opa/internal/runtime"
inmem "github.com/open-policy-agent/opa/storage/inmem/test"
"github.com/open-policy-agent/opa/util/test"
)
func BenchmarkPartialObjectRuleCrossModule(b *testing.B) {
ctx := context.Background()
sizes := []int{10, 100, 1000}
for _, n := range sizes {
b.Run(fmt.Sprint(n), func(b *testing.B) {
store := inmem.NewFromObject(map[string]interface{}{})
mods := test.PartialObjectBenchmarkCrossModule(n)
query := "data.test.foo"
input := make(map[string]interface{})
for idx := 0; idx <= 3; idx++ {
input[fmt.Sprintf("test_input_%d", idx)] = "test_input_10"
}
inputAST, err := ast.InterfaceToValue(input)
if err != nil {
b.Fatal(err)
}
compiler := ast.MustCompileModules(map[string]string{
"test/foo.rego": mods[0],
"test/bar.rego": mods[1],
"test/baz.rego": mods[2],
})
info, err := runtime.Term(runtime.Params{})
if err != nil {
b.Fatal(err)
}
pq, err := New(
Query(query),
Compiler(compiler),
Store(store),
Runtime(info),
).PrepareForEval(ctx)
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err = pq.Eval(
ctx,
EvalParsedInput(inputAST),
EvalRuleIndexing(true),
EvalEarlyExit(true),
)
if err != nil {
b.Fatal(err)
}
}
})
}
}