2022-08-25 17:04:07 +02:00
|
|
|
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
2022-09-02 21:02:19 +02:00
|
|
|
use itertools::Itertools;
|
2022-12-16 12:54:22 +01:00
|
|
|
|
|
|
|
fn interpret(code: &str) {
|
|
|
|
tvix_eval::Evaluation::new(code).evaluate()
|
|
|
|
}
|
2022-08-25 17:04:07 +02:00
|
|
|
|
|
|
|
fn eval_literals(c: &mut Criterion) {
|
2022-09-18 21:59:59 +02:00
|
|
|
c.bench_function("int", |b| {
|
|
|
|
b.iter(|| black_box(interpret("42", None, Default::default())))
|
|
|
|
});
|
2022-08-25 17:04:07 +02:00
|
|
|
}
|
|
|
|
|
2022-09-02 21:02:19 +02:00
|
|
|
fn eval_merge_attrs(c: &mut Criterion) {
|
|
|
|
c.bench_function("merge small attrs", |b| {
|
2022-09-18 21:59:59 +02:00
|
|
|
b.iter(|| {
|
|
|
|
black_box(interpret(
|
|
|
|
"{ a = 1; b = 2; } // { c = 3; }",
|
|
|
|
None,
|
|
|
|
Default::default(),
|
|
|
|
))
|
|
|
|
})
|
2022-09-02 21:02:19 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
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; }}");
|
2022-09-18 21:59:59 +02:00
|
|
|
b.iter(move || black_box(interpret(&expr, None, Default::default())))
|
2022-09-02 21:02:19 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
criterion_group!(benches, eval_literals, eval_merge_attrs);
|
2022-08-25 17:04:07 +02:00
|
|
|
criterion_main!(benches);
|