summaryrefslogtreecommitdiff
path: root/plugins/warp/benches/convert.rs
blob: d1bf9dd694cc8d3f8818906d2b6af7b2a9e14dac (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
use binaryninja::headless::Session;
use criterion::{criterion_group, criterion_main, Criterion};
use std::path::PathBuf;
use warp_ninja::convert::from_bn_type;

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

pub fn type_conversion_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");

        // Bench function types.
        let functions: Vec<_> = view.functions().iter().map(|f| f.to_owned()).collect();
        c.bench_function("type conversion all functions", |b| {
            b.iter(|| {
                for func in &functions {
                    from_bn_type(&view, &func.function_type(), u8::MAX);
                }
            })
        });

        // Bench view types.
        let types = view.types().to_vec();
        c.bench_function("type conversion all types", |b| {
            b.iter(|| {
                for ty in &types {
                    from_bn_type(&view, &ty.ty, u8::MAX);
                }
            })
        });
    }
}

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