about summary refs log tree commit diff
path: root/tvix/eval/benches/eval.rs
blob: 006038490df44bb8ca9082635f1e658768df71b6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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);