43b9e25025
Have a Evaluation::new() function that's used to set up the Evaluation struct initially - which is also used by both new_pure and new_impure internally. It's generic over the exact type of IO, making it easier to instantiate Evaluation with non-tvix-eval EvalIO implementations, that might not be in a Box. Change-Id: Ibf728da24aca59639c5b6df58d00ae98c99a63f5 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10640 Reviewed-by: raitobezarius <tvl@lahfa.xyz> Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
36 lines
974 B
Rust
36 lines
974 B
Rust
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
|
use itertools::Itertools;
|
|
|
|
fn interpret(code: &str) {
|
|
tvix_eval::Evaluation::new_pure().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);
|