Commit d8a835a5 authored by Joonas Koivunen's avatar Joonas Koivunen
Browse files

refactor: use parametrized benches, throughput

parent 0fcfbe28
......@@ -3,28 +3,47 @@ extern crate core;
extern crate criterion;
use core::hash::Hasher;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput, BenchmarkId};
fn gigabyte(c: &mut Criterion) {
c.bench_function("buffer", |b| {
b.iter({
let buf = [15; 4096];
move || {
black_box(seahash::hash(&buf));
}
})
});
c.bench_function("gigabyte_stream", |b| b.iter(|| {
let mut buf = [15;4096];
let mut hasher = seahash::SeaHasher::default();
for _ in 0..250_000 {
Hasher::write(&mut hasher,&buf);
buf[0] += buf[0].wrapping_add(1);
}
hasher.finish()
}));
let buf = vec![15; 4 * 4096];
let sizes = [8, 64, 1024, 4096, 4 * 4096];
let mut group = c.benchmark_group("buffer");
for size in &sizes {
group.throughput(Throughput::Bytes(*size as u64));
group.bench_with_input(BenchmarkId::from_parameter(size), size, |b, &size| {
b.iter(|| {
black_box(seahash::hash(&buf[..size]));
})
});
}
group.finish();
let mut group = c.benchmark_group("stream");
for size in &sizes {
group.throughput(Throughput::Bytes(*size as u64));
group.bench_with_input(BenchmarkId::from_parameter(size), size, |b, &size| {
b.iter_with_setup(
|| seahash::SeaHasher::default(),
|mut h: seahash::SeaHasher| {
// use chunks of 32 bytes to simulate some looping on a single hasher value
for _ in 0..size/32 {
h.write(&buf[..32]);
}
// this will mostly be an empty slice, but that is a possible Hasher api usage
h.write(&buf[..(size % 32)]);
black_box(h.finish())
})
});
}
group.finish();
}
criterion_group!(benches, gigabyte);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment