forked from open-policy-agent/opa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile_bench_test.go
47 lines (38 loc) · 1.12 KB
/
compile_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
package ast
import (
"fmt"
"testing"
)
func BenchmarkRewriteDynamics(b *testing.B) {
// The choice of query to use is somewhat arbitrary. This query is
// representative of the ones that result from partial evaluation on IAM
// data models (e.g., a triple glob match on subject/action/resource.)
body := MustParseBody(`
glob.match("a:*", [":"], input.abcdef.x12345);
glob.match("a:*", [":"], input.abcdef.y12345);
glob.match("a:*", [":"], input.abcdef.z12345)
`)
sizes := []int{1, 10, 100, 1000, 10000, 100000}
queries := makeQueriesForRewriteDynamicsBenchmark(sizes, body)
for i := range sizes {
b.Run(fmt.Sprint(sizes[i]), func(b *testing.B) {
factory := newEqualityFactory(newLocalVarGenerator(nil))
b.ResetTimer()
for n := 0; n < b.N; n++ {
for _, body := range queries[i] {
rewriteDynamics(factory, body)
}
}
})
}
}
func makeQueriesForRewriteDynamicsBenchmark(sizes []int, body Body) [][]Body {
queries := make([][]Body, len(sizes))
for i := range queries {
queries[i] = make([]Body, sizes[i])
for j := 0; j < sizes[i]; j++ {
queries[i][j] = body.Copy()
}
}
return queries
}