From 2a93356dcde943f35b198d5388cfab6e6deba6e4 Mon Sep 17 00:00:00 2001 From: Olivier Giniaux Date: Thu, 14 Nov 2024 00:26:45 +0100 Subject: [PATCH] Add foldhash to bench --- Cargo.toml | 1 + benches/quality/main.rs | 4 ++++ benches/throughput/main.rs | 8 +++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 293e366..2aeefea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,7 @@ highway = "1.2.0" seahash = "4.1.0" metrohash = "1.0.6" fnv = "1.0.7" +foldhash = "0.1.3" [dev-dependencies.plotters] version = "0.3.7" diff --git a/benches/quality/main.rs b/benches/quality/main.rs index 16c4517..ce8d8f7 100644 --- a/benches/quality/main.rs +++ b/benches/quality/main.rs @@ -3,12 +3,16 @@ use rand::Rng; use criterion::black_box; fn main() { + // Passing hash functions ✅ bench_hasher_quality::("GxHash"); bench_hasher_quality::("Default"); bench_hasher_quality::("XxHash (XXH3)"); bench_hasher_quality::("AHash"); bench_hasher_quality::("T1ha"); + + // Not passing hash functions ❌ bench_hasher_quality::("FNV-1a"); + bench_hasher_quality::("FoldHash"); } macro_rules! check { diff --git a/benches/throughput/main.rs b/benches/throughput/main.rs index bc3a3fb..bdd423f 100644 --- a/benches/throughput/main.rs +++ b/benches/throughput/main.rs @@ -3,7 +3,7 @@ mod result_processor; use result_processor::*; use std::hint::black_box; -use std::hash::Hasher; +use std::hash::{BuildHasher, Hasher}; use std::time::{Instant, Duration}; use std::alloc::{alloc, dealloc, Layout}; use std::slice; @@ -47,6 +47,12 @@ fn main() { benchmark(processor.as_mut(), slice, "XxHash (XXH3)", |data: &[u8], seed: u64| -> u64 { twox_hash::xxh3::hash64_with_seed(data, seed) }); + + // FoldHash + let foldhash_hasher: foldhash::quality::RandomState = foldhash::quality::RandomState::default(); + benchmark(processor.as_mut(), slice, "FoldHash", |data: &[u8], _: i32| -> u64 { + foldhash_hasher.hash_one(data) + }); // AHash let ahash_hasher = ahash::RandomState::with_seed(42);