feat(tvix/eval/benches): benchmark intersectAttrs
Change-Id: If5da2c4022758900a0d0167835ff7a61613e05a4 Reviewed-on: https://cl.snix.dev/c/snix/+/30373 Tested-by: besadii Reviewed-by: Florian Klink <flokli@flokli.de>
This commit is contained in:
parent
853754d25f
commit
0e32b4d72d
1 changed files with 56 additions and 1 deletions
|
|
@ -38,5 +38,60 @@ fn eval_merge_attrs(c: &mut Criterion) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
criterion_group!(benches, eval_literals, eval_merge_attrs);
|
fn eval_intersect_attrs(c: &mut Criterion) {
|
||||||
|
c.bench_function("intersect small attrs", |b| {
|
||||||
|
b.iter(|| {
|
||||||
|
interpret(black_box(
|
||||||
|
"builtins.intersectAttrs { a = 1; b = 2; } { c = 3; }",
|
||||||
|
));
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
c.bench_function("intersect large attrs with small attrs", |b| {
|
||||||
|
let large_attrs = format!(
|
||||||
|
"{{{}}}",
|
||||||
|
(0..10000).map(|n| format!("a{n} = {n};")).join(" ")
|
||||||
|
);
|
||||||
|
let expr = format!("builtins.intersectAttrs {large_attrs} {{ c = 3; }}");
|
||||||
|
b.iter(move || {
|
||||||
|
interpret(black_box(&expr));
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
c.bench_function("intersect large attrs with large attrs", |b| {
|
||||||
|
// the intersection is 2n=3m, which is about ~⅓ of the union, and ~¼ of the elements < 2*1e4
|
||||||
|
|
||||||
|
let left_attrs = format!(
|
||||||
|
"{{{}}}",
|
||||||
|
(0..10000)
|
||||||
|
.map(|n| {
|
||||||
|
let i = 2 * n;
|
||||||
|
format!("a{i} = {i};")
|
||||||
|
})
|
||||||
|
.join(" ")
|
||||||
|
);
|
||||||
|
|
||||||
|
let right_attrs = format!(
|
||||||
|
"{{{}}}",
|
||||||
|
(0..10000)
|
||||||
|
.map(|m| {
|
||||||
|
let j = 3 * m;
|
||||||
|
format!("a{j} = {j};")
|
||||||
|
})
|
||||||
|
.join(" ")
|
||||||
|
);
|
||||||
|
|
||||||
|
let expr = format!("builtins.intersectAttrs {left_attrs} {right_attrs}");
|
||||||
|
b.iter(move || {
|
||||||
|
interpret(black_box(&expr));
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
criterion_group!(
|
||||||
|
benches,
|
||||||
|
eval_literals,
|
||||||
|
eval_merge_attrs,
|
||||||
|
eval_intersect_attrs
|
||||||
|
);
|
||||||
criterion_main!(benches);
|
criterion_main!(benches);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue