Skip to content

Commit

Permalink
Add highwayhash to benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
ogxd committed Oct 28, 2023
1 parent 043d298 commit 873ad41
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ lazy_static = { version = "1.3" }
ahash = "0.8.3"
t1ha = "0.1.0"
twox-hash = "1.6.3"
highway = "1.1.0"

[[bench]]
name = "throughput"
Expand Down
23 changes: 14 additions & 9 deletions benches/throughput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,19 @@ mod fnv;
fn benchmark<F>(c: &mut BenchmarkGroup<WallTime>, data: &[u8], name: &str, delegate: F)
where F: Fn(&[u8], i32) -> u64
{
for i in 1..16 {
for i in 1.. {
let len = usize::pow(4, i);
if len > data.len() {
break;
}

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

let aligned_slice = &data[0..len];
c.bench_with_input(BenchmarkId::new(name, len), aligned_slice, |bencher, input| {
let slice = &data[0..len]; // Aligned
// let slice = &data[1..len]; // Unaligned
c.bench_with_input(BenchmarkId::new(name, len), slice, |bencher, input| {
bencher.iter(|| black_box(delegate(input, 0)))
});

// let unaligned_slice = &slice[1..len];
// group.bench_with_input(format!("{} bytes (unaligned)", len), unaligned_slice, |bencher, input| {
// bencher.iter(|| black_box(gxhash(input)))
// });
}
}

Expand All @@ -50,7 +49,7 @@ fn benchmark_all(c: &mut Criterion) {
// });

// GxHash1
benchmark(&mut group, slice, "gxhash1", |data: &[u8], _: i32| -> u64 {
benchmark(&mut group, slice, "gxhash", |data: &[u8], _: i32| -> u64 {
gxhash1_64(data, 0)
});

Expand All @@ -70,6 +69,12 @@ fn benchmark_all(c: &mut Criterion) {
twox_hash::xxh3::hash64_with_seed(data, seed as u64)
});

// HighwayHash
benchmark(&mut group, slice, "highwayhash", |data: &[u8], _: i32| -> u64 {
use highway::{HighwayHasher, HighwayHash};
HighwayHasher::default().hash64(data)
});

// FNV-1a
benchmark(&mut group, slice, "fnv-1a", |data: &[u8], _: i32| -> u64 {
fnv::fnv_hash(data)
Expand Down

0 comments on commit 873ad41

Please sign in to comment.