tvl-depot/tvix/eval/benches/eval.rs
Aspen Smith e66dcba195 fix(tvix/eval): Update eval benches for new API
cl/10475 updated the API of tvix_eval::Evaluation, but didn't update
this benchmark to use that new API.

Also, fixes the docstring to no longer specify that there is a "given
snippet".

Change-Id: Ibb8285731849dbeec814e2585bbaa36f22368afe
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10542
Autosubmit: aspen <root@gws.fyi>
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Reviewed-by: flokli <flokli@flokli.de>
2024-01-05 16:30:51 +00:00

36 lines
973 B
Rust

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use itertools::Itertools;
fn interpret(code: &str) {
tvix_eval::Evaluation::default().evaluate(code, None);
}
fn eval_literals(c: &mut Criterion) {
c.bench_function("int", |b| {
b.iter(|| {
interpret(black_box("42"));
})
});
}
fn eval_merge_attrs(c: &mut Criterion) {
c.bench_function("merge small attrs", |b| {
b.iter(|| {
interpret(black_box("{ a = 1; b = 2; } // { c = 3; }"));
})
});
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(black_box(&expr));
})
});
}
criterion_group!(benches, eval_literals, eval_merge_attrs);
criterion_main!(benches);