257c67f204
In //tvix/eval: * criterion bumped to 4.0, which at least depends on clap 3.x instead of 2.x, which is less incompatible In //tvix/cli: * no changes required In //tvix/nix_cli: * some minor changes for compatibility with clap 4.0, no functionality changes Change-Id: If793f64b59fcaa2402d3d483ddbab4092f32df03 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7588 Reviewed-by: grfn <grfn@gws.fyi> Tested-by: BuildkiteCI
36 lines
1 KiB
Rust
36 lines
1 KiB
Rust
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
|
use itertools::Itertools;
|
|
|
|
fn interpret(code: &str) {
|
|
tvix_eval::Evaluation::new(code).evaluate()
|
|
}
|
|
|
|
fn eval_literals(c: &mut Criterion) {
|
|
c.bench_function("int", |b| {
|
|
b.iter(|| black_box(interpret("42", None, Default::default())))
|
|
});
|
|
}
|
|
|
|
fn eval_merge_attrs(c: &mut Criterion) {
|
|
c.bench_function("merge small attrs", |b| {
|
|
b.iter(|| {
|
|
black_box(interpret(
|
|
"{ a = 1; b = 2; } // { c = 3; }",
|
|
None,
|
|
Default::default(),
|
|
))
|
|
})
|
|
});
|
|
|
|
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 || black_box(interpret(&expr, None, Default::default())))
|
|
});
|
|
}
|
|
|
|
criterion_group!(benches, eval_literals, eval_merge_attrs);
|
|
criterion_main!(benches);
|