diff options
Diffstat (limited to 'plugins/warp/benches')
| -rw-r--r-- | plugins/warp/benches/convert.rs | 39 | ||||
| -rw-r--r-- | plugins/warp/benches/function.rs | 42 | ||||
| -rw-r--r-- | plugins/warp/benches/guid.rs | 22 |
3 files changed, 103 insertions, 0 deletions
diff --git a/plugins/warp/benches/convert.rs b/plugins/warp/benches/convert.rs new file mode 100644 index 00000000..e916d5df --- /dev/null +++ b/plugins/warp/benches/convert.rs @@ -0,0 +1,39 @@ +use binaryninja::binaryview::BinaryViewExt; +use binaryninja::headless::Session; +use binaryninja::types::Conf; +use criterion::{criterion_group, criterion_main, Criterion}; +use std::path::PathBuf; +use warp_ninja::convert::from_bn_type; + +pub fn type_conversion_benchmark(c: &mut Criterion) { + let session = Session::new(); + let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap(); + for entry in std::fs::read_dir(out_dir).expect("Failed to read OUT_DIR") { + let entry = entry.expect("Failed to read directory entry"); + let path = entry.path(); + if path.is_file() { + if let Some(bv) = session.load(path.to_str().unwrap()) { + let functions = bv.functions(); + c.bench_function("type conversion all functions", |b| { + b.iter(|| { + for func in &functions { + from_bn_type(&bv, func.function_type(), u8::MAX); + } + }) + }); + + let types = bv.types(); + c.bench_function("type conversion all types", |b| { + b.iter(|| { + for ty in &types { + from_bn_type(&bv, ty.type_object().clone(), u8::MAX); + } + }) + }); + } + } + } +} + +criterion_group!(benches, type_conversion_benchmark); +criterion_main!(benches); diff --git a/plugins/warp/benches/function.rs b/plugins/warp/benches/function.rs new file mode 100644 index 00000000..c6f6d70d --- /dev/null +++ b/plugins/warp/benches/function.rs @@ -0,0 +1,42 @@ +use binaryninja::binaryview::BinaryViewExt; +use binaryninja::headless::Session; +use criterion::{criterion_group, criterion_main, Criterion}; +use rayon::prelude::*; +use warp_ninja::build_function; +use warp_ninja::cache::FunctionCache; + +pub fn function_benchmark(c: &mut Criterion) { + let session = Session::new(); + let bv = session.load(env!("TEST_BIN_LIBRARY_OBJ")).unwrap(); + let functions = bv.functions(); + assert_eq!(functions.len(), 6); + let mut function_iter = functions.into_iter(); + let first_function = function_iter.next().unwrap(); + + c.bench_function("signature first function", |b| { + b.iter(|| { + let _ = build_function(&first_function, &first_function.low_level_il().unwrap()); + }) + }); + + c.bench_function("signature all functions", |b| { + b.iter(|| { + for func in &functions { + let _ = build_function(&func, &func.low_level_il().unwrap()); + } + }) + }); + + let cache = FunctionCache::default(); + c.bench_function("signature all functions rayon", |b| { + b.iter(|| { + functions + .par_iter() + .map_with(cache.clone(), |par_cache, func| par_cache.function(&func)) + .collect::<Vec<_>>() + }) + }); +} + +criterion_group!(benches, function_benchmark); +criterion_main!(benches); diff --git a/plugins/warp/benches/guid.rs b/plugins/warp/benches/guid.rs new file mode 100644 index 00000000..577f80b5 --- /dev/null +++ b/plugins/warp/benches/guid.rs @@ -0,0 +1,22 @@ +use binaryninja::binaryview::BinaryViewExt; +use binaryninja::headless::Session; +use criterion::{criterion_group, criterion_main, Criterion}; +use warp_ninja::function_guid; + +pub fn guid_benchmark(c: &mut Criterion) { + let session = Session::new(); + let bv = session.load(env!("TEST_BIN_LIBRARY_OBJ")).unwrap(); + let functions = bv.functions(); + assert_eq!(functions.len(), 6); + let mut function_iter = functions.into_iter(); + let first_function = function_iter.next().unwrap(); + + c.bench_function("function guid", |b| { + b.iter(|| { + function_guid(&first_function, &vec![]); + }) + }); +} + +criterion_group!(benches, guid_benchmark); +criterion_main!(benches); |
