Commit db709305 authored by Tom Almeida's avatar Tom Almeida

Merge branch 'use_criterion' into 'master'

benches: Use criterion

See merge request !6
parents e365d543 994214b3
Pipeline #8754 failed with stage
in 9 seconds
......@@ -11,7 +11,12 @@ exclude = ["target", "Cargo.lock"]
[dev-dependencies]
quickcheck = "0.9.2"
criterion = "0.3"
[features]
default = []
use_std = []
[[bench]]
name = "bench"
harness = false
extern crate core;
extern crate criterion;
extern crate seahash;
use core::hash::Hasher;
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
fn describe_benches(c: &mut Criterion) {
// shared buffers for all tests
let buf = vec![15; 16 * 1024];
// shared/n and buffer/n are executed for these sizes
let sizes = [64, 1024, 4096, 16 * 1024];
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();
// gigabyte group times are comparable with earlier benchmark values based on
// d52d115a223a0e81d1600bd8a5e73cb4b24a38c0
let mut group = c.benchmark_group("gigabyte");
group.throughput(Throughput::Bytes((1024 * 1024 * 1024) as u64));
group.bench_function(BenchmarkId::from_parameter("buffer"), |b| {
b.iter(|| {
let mut buf = [15; 4096];
let mut total = 0;
for _ in 0..250_000 {
total ^= seahash::hash(&buf);
buf[0] = buf[0].wrapping_add(1);
}
black_box(total)
})
});
group.bench_function(BenchmarkId::from_parameter("stream"), |b| {
b.iter(|| {
let mut buf = [15; 4096];
let mut h = seahash::SeaHasher::default();
for _ in 0..250_000 {
h.write(&buf);
buf[0] = buf[0].wrapping_add(1);
}
black_box(h.finish())
})
});
group.finish();
}
criterion_group!(benches, describe_benches);
criterion_main!(benches);
#![feature(test)]
extern crate test;
extern crate seahash;
extern crate core;
use core::hash::Hasher;
#[bench]
fn gigabyte(b: &mut test::Bencher) {
b.iter(|| {
let mut x = 0;
let mut buf = [15; 4096];
for _ in 0..250000 {
x ^= seahash::hash(&buf);
buf[0] += buf[0].wrapping_add(1);
}
x
})
}
#[bench]
fn gigabyte_stream(b: &mut test::Bencher) {
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()
})
}
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