aboutsummaryrefslogtreecommitdiffstats
path: root/benches/sylt_benchmark.rs
blob: e77a91632e8e8b9360364f5804de3158d33a69cb (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
use criterion::{criterion_group, criterion_main, Criterion};
use std::fs;
use std::path::Path;

macro_rules! bench_file {
    ( $name:ident ) => {
        pub fn $name(c: &mut Criterion) {
            let prog = fs::read_to_string(Path::new(&format!("progs/bench/{}.sy", stringify!($name))))
                .unwrap();
            c.bench_function(stringify!($name), |b| {
                b.iter(|| {
                    sylt::run_string(&prog, false, Vec::new()).unwrap();
                })
            });
        }
    };
}

macro_rules! bench {
    ( [ $( $name:ident ),* ] ) => {
        $(bench_file!($name);)*

        criterion_group!(benches, $( $name ),* );
        criterion_main!(benches);
    }
}

// List of all benchmarks to run
bench!([fib, fib_iter, sum]);