Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dustoff ahash-compare #165

Merged
merged 6 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading