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;
|
2024-02-13 19:23:39 +01:00
|
|
|
#[cfg(not(target_env = "msvc"))]
|
|
|
|
use tikv_jemallocator::Jemalloc;
|
|
|
|
|
|
|
|
#[cfg(not(target_env = "msvc"))]
|
|
|
|
#[global_allocator]
|
|
|
|
static GLOBAL: Jemalloc = Jemalloc;
|
2022-12-16 12:54:22 +01:00
|
|
|
|
|
|
|
fn interpret(code: &str) {
|
2024-01-16 14:35:44 +01:00
|
|
|
tvix_eval::Evaluation::new_pure().evaluate(code, None);
|
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(|| {
|
2023-11-02 21:28:26 +01:00
|
|
|
interpret(black_box("42"));
|
2022-12-20 15:22:56 +01:00
|
|
|
})
|
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(|| {
|
2023-11-02 21:28:26 +01:00
|
|
|
interpret(black_box("{ a = 1; b = 2; } // { c = 3; }"));
|
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 || {
|
2023-11-02 21:28:26 +01:00
|
|
|
interpret(black_box(&expr));
|
2022-12-20 15:22:56 +01:00
|
|
|
})
|
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);
|