From d9b5c3ff8ce4acae3d2de0de53f5f023818b29c0 Mon Sep 17 00:00:00 2001 From: Chris Ha Date: Sat, 21 Oct 2023 16:41:06 +0900 Subject: [PATCH] dustoff ahash-compare (#165) fixes some issues that block building ahash-compare updates dependencies replace twoxhash with the newer xxhash-rust --- compare/Cargo.toml | 9 ++++----- compare/tests/compare.rs | 24 +++++++++++------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/compare/Cargo.toml b/compare/Cargo.toml index d2ba3b5..88bdf19 100644 --- a/compare/Cargo.toml +++ b/compare/Cargo.toml @@ -13,7 +13,6 @@ readme = "README.md" [features] default = ["std"] std = ["ahash/std"] -nightly = ["ahash/specialize"] compile-time-rng = ["ahash/compile-time-rng"] [[bench]] @@ -36,9 +35,9 @@ criterion = "0.3.3" fnv = "1.0.7" fxhash = "0.2.1" farmhash = "1.1.5" -highway = "0.5.0" +highway = "1.1.0" metrohash = "1.0.6" -siphasher = "0.3.3" +siphasher = "1" t1ha = "0.1.0" -wyhash = "0.4.1" -twox-hash = "1.6.0" +wyhash = "0.5" +xxhash-rust = {version = "0.8", features = ["xxh3"]} diff --git a/compare/tests/compare.rs b/compare/tests/compare.rs index 273624c..294a8d4 100644 --- a/compare/tests/compare.rs +++ b/compare/tests/compare.rs @@ -1,13 +1,15 @@ -use ahash::{CallHasher, RandomState}; +use ahash::RandomState; use criterion::*; use farmhash::FarmHasher; -use fnv::{FnvBuildHasher}; +use fnv::FnvBuildHasher; use fxhash::FxBuildHasher; use std::hash::{BuildHasher, BuildHasherDefault, Hash, Hasher}; +use xxhash_rust::xxh3::Xxh3Builder; fn ahash(k: &K, builder: &RandomState) -> u64 { - let hasher = builder.build_hasher(); - k.get_hash(hasher) + let mut hasher = builder.build_hasher(); + k.hash(&mut hasher); + hasher.finish() } fn generic_hash(key: &K, builder: &B) -> u64 { @@ -28,25 +30,21 @@ fn create_string(len: usize) -> String { fn compare_ahash(c: &mut Criterion) { let builder = RandomState::new(); let test = "compare_ahash"; - for num in &[1,3,7,15,31,63,127,255,511,1023] { + for num in &[1, 3, 7, 15, 31, 63, 127, 255, 511, 1023] { let name = "string".to_owned() + &num.to_string(); let string = create_string(*num); c.bench_with_input(BenchmarkId::new(test, &name), &string, |bencher, s| { - bencher.iter(|| { - black_box(ahash(s, &builder)) - }); + bencher.iter(|| black_box(ahash(s, &builder))); }); } } fn compare_other(c: &mut Criterion, test: &str, builder: B) { - for num in &[1,3,7,15,31,63,127,255,511,1023] { + for num in &[1, 3, 7, 15, 31, 63, 127, 255, 511, 1023] { let name = "string".to_owned() + &num.to_string(); let string = create_string(*num); c.bench_with_input(BenchmarkId::new(test, &name), &string, |bencher, s| { - bencher.iter(|| { - black_box(generic_hash(&s, &builder)) - }); + bencher.iter(|| black_box(generic_hash(&s, &builder))); }); } } @@ -117,7 +115,7 @@ fn compare_wyhash(c: &mut Criterion) { fn compare_xxhash(c: &mut Criterion) { let int: u64 = 1234; let string = create_string(1024); - let builder = twox_hash::RandomXxHashBuilder64::default(); + let builder = Xxh3Builder::default(); compare_other(c, "compare_xxhash", builder) }