Skip to content

Commit

Permalink
Add fnv, seahash and metrohash to benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
ogxd committed Nov 4, 2023
1 parent 103a493 commit 4c55b1d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 32 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ ahash = "0.8.3"
t1ha = "0.1.0"
twox-hash = "1.6.3"
highway = "1.1.0"
seahash = "4.1.0"
metrohash = "1.0.6"
fnv = "1.0.3"

[[bench]]
name = "throughput"
Expand Down
14 changes: 0 additions & 14 deletions benches/fnv.rs

This file was deleted.

25 changes: 19 additions & 6 deletions benches/throughput/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
include!("../fnv.rs");

mod result_processor;

use result_processor::*;
Expand All @@ -8,6 +6,7 @@ use std::hint::black_box;
use std::time::{Instant, Duration};
use std::alloc::{alloc, dealloc, Layout};
use std::slice;
use std::hash::Hasher;

use rand::Rng;

Expand Down Expand Up @@ -35,6 +34,11 @@ fn main() {
benchmark(&mut processor, slice, algo_name, |data: &[u8], seed: i32| -> u64 {
gxhash64(data, seed)
});

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

// AHash
let ahash_hasher = ahash::RandomState::with_seeds(0, 0, 0, 0);
Expand All @@ -47,9 +51,16 @@ fn main() {
t1ha::t1ha0(data, seed as u64)
});

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

// MetroHash
benchmark(&mut processor, slice, "metrohash", |data: &[u8], seed: i32| -> u64 {
let mut metrohash_hasher = metrohash::MetroHash64::with_seed(seed as u64);
metrohash_hasher.write(data);
metrohash_hasher.finish()
});

// HighwayHash
Expand All @@ -60,7 +71,9 @@ fn main() {

// FNV-1a
benchmark(&mut processor, slice, "fnv-1a", |data: &[u8], seed: i32| -> u64 {
fnv_hash(data, seed as u64)
let mut fnv_hasher = fnv::FnvHasher::with_key(seed as u64);
fnv_hasher.write(data);
fnv_hasher.finish()
});

// Free benchmark data
Expand Down
6 changes: 4 additions & 2 deletions benches/throughput_criterion.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::time::Duration;
use std::alloc::{alloc, dealloc, Layout};
use std::slice;
use std::hash::Hasher;

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

use gxhash::*;
mod fnv;

fn benchmark<F>(c: &mut BenchmarkGroup<WallTime>, data: &[u8], name: &str, delegate: F)
where F: Fn(&[u8], i32) -> u64
Expand Down Expand Up @@ -73,7 +73,9 @@ fn benchmark_all(c: &mut Criterion) {

// FNV-1a
benchmark(&mut group, slice, "fnv-1a", |data: &[u8], seed: i32| -> u64 {
fnv::fnv_hash(data, seed as u64)
let mut fnv_hasher = fnv::FnvHasher::with_key(seed as u64);
fnv_hasher.write(data);
fnv_hasher.finish()
});

group.finish();
Expand Down
19 changes: 9 additions & 10 deletions src/gxhash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,6 @@ unsafe fn gxhash_process_8(mut ptr: *const State, hash_vector: State, remaining_
tmp = compress_fast(tmp, v6);
tmp = compress_fast(tmp, v7);

// let t1 = compress(v0, v3);
// let t2 = compress(v2, v1);
// let t3 = compress(v4, v7);
// let t4 = compress(v6, v5);

// let t5 = compress_fast(t1, t3);
// let t6 = compress_fast(t2, t4);

// let tmp = compress_fast(t6, t5);

hash_vector = compress(hash_vector, tmp);
}

Expand Down Expand Up @@ -249,4 +239,13 @@ mod tests {
assert_ne!(0, gxhash32(&[0u8; 1], 0));
assert_ne!(0, gxhash32(&[0u8; 1200], 0));
}

// GxHash with a 128-bit state must be stable despite the different endianesses / CPU instrinsics
#[cfg(not(feature = "avx2"))]
#[test]
fn is_stable() {
assert_eq!(456576800, gxhash32(&[0u8; 0], 0));
assert_eq!(978957914, gxhash32(&[0u8; 1], 0));
assert_eq!(3128839713, gxhash32(&[42u8; 1000], 1234));
}
}

0 comments on commit 4c55b1d

Please sign in to comment.