Skip to content

Commit

Permalink
Add benchmarks for Context
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanUkhov committed Apr 29, 2024
1 parent b63363e commit 0f5f921
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions benches/lib.rs
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());
});
}

0 comments on commit 0f5f921

Please sign in to comment.