Skip to content

Commit 4008842

Browse files
committed
rs: add disasm_iter to benchmark
Benchmarking result on i9-14900K: disasm_x86 time: [2.7127 ms 2.7144 ms 2.7167 ms] disasm_x86_iter time: [2.6826 ms 2.6839 ms 2.6855 ms] disasm_x86_detail time: [10.215 ms 10.228 ms 10.241 ms] disasm_x86_detail_iter time: [3.8006 ms 3.8027 ms 3.8052 ms]
1 parent 336e650 commit 4008842

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

capstone-rs/benches/my_benchmark.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,42 @@ fn arch_bench<T: Iterator<Item = ExtraMode>>(
1616
extra_mode: T,
1717
endian: Option<Endian>,
1818
detail: bool,
19+
iter: bool,
1920
) {
2021
let mut cs =
2122
Capstone::new_raw(arch, mode, extra_mode, endian).expect("failed to make capstone");
2223
cs.set_detail(detail).expect("failed to set detail");
2324

24-
let insns = cs.disasm_all(code, 0x1000).expect("failed to disassemble");
25-
for i in insns.iter() {
26-
black_box(i);
25+
if iter {
26+
let iter = cs.disasm_iter(code, 0x1000).expect("failed to disassemble");
27+
for i in iter {
28+
black_box(i);
29+
}
30+
} else {
31+
let insns = cs.disasm_all(code, 0x1000).expect("failed to disassemble");
32+
for i in insns.iter() {
33+
black_box(i);
34+
}
2735
}
2836
}
2937

3038
fn criterion_benchmark(c: &mut Criterion) {
3139
macro_rules! bench {
3240
($name:expr; $( $args:expr ),+ ) => {
3341
c.bench_function($name, |b| {
34-
b.iter(|| arch_bench($( $args, )+ false))
42+
b.iter(|| arch_bench($( $args, )+ false, false))
43+
});
44+
45+
c.bench_function(concat!($name, "_iter"), |b| {
46+
b.iter(|| arch_bench($( $args, )+ false, true))
3547
});
3648

3749
c.bench_function(concat!($name, "_detail"), move |b| {
38-
b.iter(|| arch_bench($( $args, )+ true))
50+
b.iter(|| arch_bench($( $args, )+ true, false))
51+
});
52+
53+
c.bench_function(concat!($name, "_detail_iter"), |b| {
54+
b.iter(|| arch_bench($( $args, )+ true, true))
3955
});
4056
}
4157
}

0 commit comments

Comments
 (0)