-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
29 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,42 @@ | ||
#![feature(test)] | ||
|
||
extern crate md5; | ||
extern crate test; | ||
|
||
#[bench] | ||
fn compute_0001000(bencher: &mut test::Bencher) { | ||
compute(1000, bencher); | ||
} | ||
use md5::Context; | ||
|
||
#[bench] | ||
fn compute_0010000(bencher: &mut test::Bencher) { | ||
compute(10000, bencher); | ||
} | ||
macro_rules! implement( | ||
($($size:literal => ($compute:ident, $context:ident),)*) => ($( | ||
#[bench] | ||
fn $compute(bencher: &mut test::Bencher) { | ||
compute($size, bencher); | ||
} | ||
|
||
#[bench] | ||
fn compute_0100000(bencher: &mut test::Bencher) { | ||
compute(100000, bencher); | ||
} | ||
#[bench] | ||
fn $context(bencher: &mut test::Bencher) { | ||
context($size, bencher); | ||
} | ||
)*); | ||
); | ||
|
||
#[bench] | ||
fn compute_1000000(bencher: &mut test::Bencher) { | ||
compute(1000000, bencher); | ||
implement! { | ||
1000 => (compute_0001000, context_0001000), | ||
10000 => (compute_0010000, context_0010000), | ||
100000 => (compute_0100000, context_0100000), | ||
1000000 => (compute_1000000, context_1000000), | ||
} | ||
|
||
fn compute(size: usize, bencher: &mut test::Bencher) { | ||
let data = &vec![0xffu8; size][..]; | ||
let data = vec![0xffu8; size]; | ||
bencher.iter(|| { | ||
test::black_box(md5::compute(&data)); | ||
}); | ||
} | ||
|
||
fn context(size: usize, bencher: &mut test::Bencher) { | ||
let data = vec![0xffu8; size]; | ||
bencher.iter(|| { | ||
test::black_box(md5::compute(data)); | ||
let mut context = Context::new(); | ||
context.consume(&data); | ||
test::black_box(context.compute()); | ||
}); | ||
} |