Skip to content

Commit

Permalink
Merge benchs
Browse files Browse the repository at this point in the history
  • Loading branch information
ogxd committed Oct 21, 2023
1 parent bc54006 commit 7d138b1
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions benches/throughput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@ use std::time::Duration;
use std::alloc::{alloc, dealloc, Layout};
use std::slice;

use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput};
use criterion::measurement::{WallTime};
use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput, PlotConfiguration, AxisScale, BenchmarkGroup};
use gxhash::*;
use rand::Rng;

fn benchmark<F>(c: &mut Criterion, data: &[u8], name: &str, delegate: F)
fn benchmark<F>(c: &mut BenchmarkGroup<WallTime>, data: &[u8], name: &str, delegate: F)
where F: Fn(&[u8], i32) -> u64
{
let mut group = c.benchmark_group(name);

for i in 1..8 {
let len = usize::pow(4, i);

group.throughput(Throughput::Bytes(len as u64));
c.throughput(Throughput::Bytes(len as u64));

let aligned_slice = &data[0..len];
group.bench_with_input(format!("{} bytes (aligned)", len), aligned_slice, |bencher, input| {
c.bench_with_input(format!("{} bytes", len), aligned_slice, |bencher, input| {
bencher.iter(|| black_box(delegate(input, 0)))
});

Expand All @@ -41,25 +40,31 @@ fn benchmark_all(c: &mut Criterion) {
// Fill with random bytes
rng.fill(slice);

let mut group = c.benchmark_group("hash algos");
let plot_config = PlotConfiguration::default().summary_scale(AxisScale::Logarithmic);
group.plot_config(plot_config);

// GxHash
benchmark(c, slice, "gxhash", gxhash64);
benchmark(&mut group, slice, "gxhash", gxhash64);

// AHash
let build_hasher = ahash::RandomState::with_seeds(0, 0, 0, 0);
benchmark(c, slice, "ahash", |data: &[u8], _: i32| -> u64 {
benchmark(&mut group, slice, "ahash", |data: &[u8], _: i32| -> u64 {
build_hasher.hash_one(data)
});

// T1ha0
benchmark(c, slice, "t1ha0", |data: &[u8], seed: i32| -> u64 {
benchmark(&mut group, slice, "t1ha0", |data: &[u8], seed: i32| -> u64 {
t1ha::t1ha0(data, seed as u64)
});

// XxHash (twox-hash)
benchmark(c, slice, "xxhash (twox-hash)", |data: &[u8], seed: i32| -> u64 {
benchmark(&mut group, slice, "xxhash (twox-hash)", |data: &[u8], seed: i32| -> u64 {
twox_hash::xxh3::hash64_with_seed(data, seed as u64)
});

group.finish();

// Free benchmark data
unsafe { dealloc(ptr, layout) };
}
Expand All @@ -68,7 +73,7 @@ criterion_group! {
name = benches;
config = Criterion::default()
.sample_size(1000)
.measurement_time(Duration::from_secs(5));
.measurement_time(Duration::from_secs(2));
targets = benchmark_all,
}
criterion_main!(benches);

0 comments on commit 7d138b1

Please sign in to comment.