about summary refs log blame commit diff
path: root/tvix/eval/benches/eval.rs
blob: 4e9be8f8f20c9033ed44ed580840b42bce80c115 (plain) (tree)
1
2
3
4
5
6
7
8
9
                                                                       
                         

                          
                                                          
 

                                     
                                 
                   
                                       
          
       

 

                                               
                   
                                                                    
          







                                                                
                        
                                        
          



                                                           
                         
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use itertools::Itertools;

fn interpret(code: &str) {
    tvix_eval::Evaluation::default().evaluate(code, None);
}

fn eval_literals(c: &mut Criterion) {
    c.bench_function("int", |b| {
        b.iter(|| {
            interpret(black_box("42"));
        })
    });
}

fn eval_merge_attrs(c: &mut Criterion) {
    c.bench_function("merge small attrs", |b| {
        b.iter(|| {
            interpret(black_box("{ a = 1; b = 2; } // { c = 3; }"));
        })
    });

    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 || {
            interpret(black_box(&expr));
        })
    });
}

criterion_group!(benches, eval_literals, eval_merge_attrs);
criterion_main!(benches);