diff options
Diffstat (limited to 'benches/handler-call.rs')
-rwxr-xr-x | benches/handler-call.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/benches/handler-call.rs b/benches/handler-call.rs new file mode 100755 index 0000000..9a9edec --- /dev/null +++ b/benches/handler-call.rs @@ -0,0 +1,32 @@ +#![feature(test)] + +extern crate test; +use test::Bencher; + +use clint::Handler; + +const ITER_COUNT: usize = 10_000; + +#[bench] +fn bench_bare_fn(b: &mut Bencher) { + static mut X: usize = 0; + #[inline(never)] + fn inc() { + unsafe { X += 1 }; + } + + let n = test::black_box(ITER_COUNT); + b.iter(|| (0..n).for_each(|_| inc())); + assert!(unsafe { X } > 0); +} + +#[bench] +fn bench_handler(b: &mut Bencher) { + static mut X: usize = 0; + let mut handler = Handler::new(); + unsafe { handler.replace(&move || X += 1) }; + + let n = test::black_box(ITER_COUNT); + b.iter(|| (0..n).for_each(|_| unsafe { handler.call() })); + assert!(unsafe { X } > 0); +} |