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) {
|
2022-12-20 15:22:56 +01:00
|
|
|
tvix_eval::Evaluation::new(code, None).evaluate();
|
2022-12-16 12:54:22 +01:00
|
|
|
}
|
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| {
|
2022-12-20 15:22:56 +01:00
|
|
|
b.iter(|| {
|
|
|
|
interpret("42");
|
|
|
|
black_box(())
|
|
|
|
})
|
2022-09-18 21:59:59 +02:00
|
|
|
});
|
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(|| {
|
2022-12-20 15:22:56 +01:00
|
|
|
interpret("{ a = 1; b = 2; } // { c = 3; }");
|
|
|
|
black_box(())
|
2022-09-18 21:59:59 +02:00
|
|
|
})
|
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-12-20 15:22:56 +01:00
|
|
|
b.iter(move || {
|
|
|
|
interpret(&expr);
|
|
|
|
black_box(())
|
|
|
|
})
|
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);
|