summaryrefslogtreecommitdiff
path: root/plugins/warp/benches/function.rs
blob: a9cfd26a546ef58af516e78beb6c17324a460bd5 (plain)
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
37
38
39
40
41
42
43
44
45
46
47
use binaryninja::headless::Session;
use criterion::{criterion_group, criterion_main, Criterion};
use rayon::prelude::*;
use std::path::PathBuf;
use warp_ninja::build_function;

// These are the target files present in OUT_DIR
// Add the files to fixtures/bin
static TARGET_FILES: [&str; 1] = ["atox.obj"];

pub fn function_benchmark(c: &mut Criterion) {
    let session = Session::new().expect("Failed to initialize session");
    let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap();
    for file_name in TARGET_FILES {
        let path = out_dir.join(file_name);
        let view = session.load(&path).expect("Failed to load view");

        let functions: Vec<_> = view.functions().iter().map(|f| f.to_owned()).collect();
        // Bench all functions sequentially
        c.bench_function("signature all functions", |b| {
            b.iter(|| {
                for func in &functions {
                    let _ = build_function(&func, || func.lifted_il().ok(), false);
                }
            })
        });

        // Bench all functions in parallel
        c.bench_function("signature all functions rayon", |b| {
            b.iter(|| {
                functions
                    .par_iter()
                    .filter_map(|func| {
                        Some(build_function(
                            func.as_ref(),
                            || func.lifted_il().ok(),
                            false,
                        ))
                    })
                    .collect::<Vec<_>>()
            })
        });
    }
}

criterion_group!(benches, function_benchmark);
criterion_main!(benches);