tvl-depot/tvix/eval/benches/eval.rs
Vincent Ambo 71174f6626 fix(tvix/eval): fix current clippy warnings
It's been a while since the last time, so quite a lot of stuff has
accumulated here.

Change-Id: I0762827c197b30a917ff470fd8ae8f220f6ba247
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7597
Reviewed-by: grfn <grfn@gws.fyi>
Autosubmit: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
2022-12-25 18:25:06 +00:00

39 lines
1,014 B
Rust

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use itertools::Itertools;
fn interpret(code: &str) {
tvix_eval::Evaluation::new(code, None).evaluate();
}
fn eval_literals(c: &mut Criterion) {
c.bench_function("int", |b| {
b.iter(|| {
interpret("42");
black_box(())
})
});
}
fn eval_merge_attrs(c: &mut Criterion) {
c.bench_function("merge small attrs", |b| {
b.iter(|| {
interpret("{ a = 1; b = 2; } // { c = 3; }");
black_box(())
})
});
c.bench_function("merge large attrs with small attrs", |b| {
let large_attrs = format!(
"{{{}}}",
(0..10000).map(|n| format!("a{n} = {n};")).join(" ")
);
let expr = format!("{large_attrs} // {{ c = 3; }}");
b.iter(move || {
interpret(&expr);
black_box(())
})
});
}
criterion_group!(benches, eval_literals, eval_merge_attrs);
criterion_main!(benches);