Skip to content

Commit 95923dd

Browse files
committed
Add benchmark for 1284 (#1307)
Signed-off-by: Craig Disselkoen <[email protected]>
1 parent be4d70f commit 95923dd

File tree

2 files changed

+211
-0
lines changed

2 files changed

+211
-0
lines changed

cedar-policy/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ harness = false
8888
name = "extension_fn_validation"
8989
harness = false
9090

91+
[[bench]]
92+
name = "deeply_nested_est"
93+
harness = false
94+
9195
[package.metadata.docs.rs]
9296
features = ["experimental"]
9397
rustdoc-args = ["--cfg", "docsrs"]
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
/*
2+
* Copyright Cedar Contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
use cedar_policy::Policy;
18+
19+
use criterion::{black_box, criterion_group, criterion_main, Criterion};
20+
21+
// PANIC SAFETY: benchmarking
22+
#[allow(clippy::unwrap_used)]
23+
pub fn deeply_nested_est(c: &mut Criterion) {
24+
let json_str = r#"
25+
{
26+
"conditions": [
27+
{
28+
"kind": "unless",
29+
"body": {
30+
"==": {
31+
"left": {
32+
"is": [
33+
{
34+
">": [
35+
{
36+
"==": {
37+
"left": {
38+
"is": [
39+
{
40+
"+": [
41+
{
42+
">": [
43+
{
44+
"is": [
45+
{
46+
"[>": [
47+
{},
48+
{
49+
">=": {
50+
"left": {
51+
"icieaticPHHcPoHtmcPolissaticPolicHHH&HHHs": [],
52+
"QtsaPolizciessatcPolicieHHHs": [
53+
{
54+
"==": {
55+
"left": {
56+
"is": [
57+
{
58+
">": [
59+
{
60+
"==": {
61+
"left": {
62+
"is": [
63+
{
64+
"+": [
65+
{
66+
">": [
67+
{
68+
"is": [
69+
{
70+
"[>": [
71+
{},
72+
{
73+
">=": {
74+
"left": {
75+
"HHHHhHcPolictempHHHHmpHH:HHHHs": [],
76+
"QstaticPolicieaticPHHcPoHsieaticPHHcPoHtmcPolissaticPolicHHH&HHHs": [],
77+
"QtsaPolizciessatcPolicieHHHs": [
78+
{
79+
"==": {
80+
"left": {
81+
"is": [
82+
{
83+
">": [
84+
{
85+
"==": {
86+
"left": {
87+
"is": [
88+
{
89+
"+": [
90+
{
91+
">": [
92+
{
93+
"is": [
94+
{
95+
"[>": [
96+
{},
97+
{
98+
">=": {
99+
"left": {
100+
"HHHHhHcPolictempHHHHmpHH:HHHHs": [],
101+
"QstaticPolicieaticPHHcPoHsaticPolicieaticPHHcPoHsieaticPHHcPoHtmcPolissaticPolicHHH&HHHs": [],
102+
"QtsaPolizciessatcPolicieHHHs": [ ],
103+
"Q?tHHHHHHHHHHHHmplates": {},
104+
"": {},
105+
"XtLHHHHHHHHHHHHHps2 \temHHclictempHHHHHHHs": [],
106+
"QstatncPlictempHHHHHHHs": [],
107+
"QstatncPolicieaticPHHHQstatmcPolicHHHHHHs": [],
108+
"QstaPoliciessaticPolicHHHHHHs": [],
109+
"QtsassatcPolicieHHHs": [],
110+
"Q?tHHHHHHHHHHHHHHHHHHHmplates": {},
111+
"XtLHHHHHHHHHHHHHHct]is": [ ]
112+
}
113+
}
114+
}
115+
]
116+
}
117+
]
118+
}
119+
]
120+
},
121+
"-"
122+
]
123+
}
124+
]
125+
}
126+
}
127+
}
128+
]
129+
}
130+
]
131+
}
132+
}
133+
}
134+
],
135+
"Q?tHHHHHHHHHHHHmplates": {},
136+
"": {},
137+
"XtLHHHHHHHHHHHHHps2 \temHHclictempHHHHHHHs": [],
138+
"QstatncPol$cieaticPHHHQstatmcPolicHHHHHHs": [],
139+
"QstaPmliciessaticPolicHHHHHHs": [],
140+
"QtsassatcPolicieHHHs": [],
141+
"Q?tHHHHHHHHHHHHHHHHHHHmplates": {},
142+
"XtLHHHHHHHHHHHHHHct]is": [ ]
143+
}
144+
}
145+
}
146+
]
147+
}
148+
]
149+
}
150+
]
151+
},
152+
"-"
153+
]
154+
}
155+
]
156+
}
157+
}
158+
}
159+
]
160+
}
161+
]
162+
}
163+
}
164+
}
165+
],
166+
"Q?tHHHHHHHHHHHHmplates": {},
167+
"": {},
168+
"XtLHHHHHHHHHHHHHps2 \temHHct]is": [ ]
169+
}
170+
}
171+
}
172+
]
173+
}
174+
]
175+
}
176+
]
177+
},
178+
"-"
179+
]
180+
}
181+
]
182+
}
183+
}
184+
}
185+
]
186+
}
187+
]
188+
}
189+
}
190+
}
191+
}
192+
]
193+
}
194+
"#;
195+
196+
c.bench_function("Policy::from_json", |b| {
197+
b.iter(|| {
198+
let _ = Policy::from_json(
199+
None,
200+
black_box(serde_json::from_str(black_box(json_str)).unwrap()),
201+
);
202+
})
203+
});
204+
}
205+
206+
criterion_group!(benches, deeply_nested_est);
207+
criterion_main!(benches);

0 commit comments

Comments
 (0)