Skip to content

Commit

Permalink
dustoff ahash-compare (#165)
Browse files Browse the repository at this point in the history
fixes some issues that block building ahash-compare
updates dependencies
replace twoxhash with the newer xxhash-rust
  • Loading branch information
chris-ha458 authored Oct 21, 2023
1 parent a74829b commit d9b5c3f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
9 changes: 4 additions & 5 deletions compare/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ readme = "README.md"
[features]
default = ["std"]
std = ["ahash/std"]
nightly = ["ahash/specialize"]
compile-time-rng = ["ahash/compile-time-rng"]

[[bench]]
Expand All @@ -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"]}
24 changes: 11 additions & 13 deletions compare/tests/compare.rs
Original file line number Diff line number Diff line change
@@ -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: Hash>(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<K: Hash, B: BuildHasher>(key: &K, builder: &B) -> u64 {
Expand All @@ -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<B: BuildHasher>(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)));
});
}
}
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit d9b5c3f

Please sign in to comment.