Skip to content

Commit 453acbf

Browse files
committed
Add: FoldHasher comparison
1 parent 1ef3334 commit 453acbf

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

Cargo.lock

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ bench_hash = [
3737
"crc32fast", # CRC32
3838
"murmur3", # MurmurHash3
3939
"cityhash", # CityHash
40+
"foldhash", # FoldHash
4041
"bit-set", # for collision counting
4142
]
4243
bench_sequence = [
@@ -128,6 +129,10 @@ optional = true
128129
version = "0.1"
129130
optional = true
130131

132+
[dependencies.foldhash]
133+
version = "0.2"
134+
optional = true
135+
131136
[dependencies.gxhash]
132137
version = "3.4.1"
133138
optional = true

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ On Intel Sapphire Rapids CPU, on `xlsum.csv` dataset, the following numbers can
4747
| `crc32fast::hash` | 32 || 0.49 GiB/s | 8.45 GiB/s |
4848
| `xxh3::xxh3_64` | 64 || 1.08 GiB/s | 9.48 GiB/s |
4949
| `aHash::hash_one` | 64 || 1.23 GiB/s | 8.61 GiB/s |
50+
| `foldhash::hash_one` | 64 || 1.02 GiB/s | 8.24 GiB/s |
5051
| `gxhash::gxhash64` | 64 || __2.68 GiB/s__ | 9.19 GiB/s |
5152
| `stringzilla::hash` | 64 || 1.84 GiB/s | __11.23 GiB/s__ |
5253
| | | | | |
@@ -70,6 +71,7 @@ This is especially important in distributed systems, where the data is too large
7071
| Rust 🦀 | | | | |
7172
| `std::hash::DefaultHasher` | 64 || 0.51 GiB/s | 3.92 GiB/s |
7273
| `aHash::AHasher` | 64 || __1.30 GiB/s__ | __8.56 GiB/s__ |
74+
| `foldhash::FoldHasher` | 64 || 1.27 GiB/s | 8.18 GiB/s |
7375
| `crc32fast::Hasher` | 32 || 0.37 GiB/s | 8.39 GiB/s |
7476
| `stringzilla::Hasher` | 64 || 0.89 GiB/s | 6.39 GiB/s |
7577
| | | | | |

bench_hash.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The benchmarks compare the performance of different hash functions including:
1313
- aHash (both incremental and single-entry variants)
1414
- xxHash (xxh3) through the third-party `xxhash-rust` crate
1515
- gxhash (gxhash64)
16+
- FoldHash (a fast hash with good quality)
1617
- CRC32 (IEEE) via `crc32fast`
1718
- Blake3 (the only cryptographic hash in the comparison, for reference)
1819
@@ -52,6 +53,7 @@ use ahash::RandomState as AHashState;
5253
use blake3;
5354
use cityhash;
5455
use crc32fast;
56+
use foldhash;
5557
use gxhash;
5658
use murmur3;
5759
use stringzilla::sz;
@@ -247,6 +249,20 @@ fn bench_stateless(
247249
print_collision_rate(&unique_tokens, |t| gxhash::gxhash64(t, 42));
248250
}
249251

252+
// Benchmark: FoldHash
253+
if should_run("stateless/foldhash::hash_one") {
254+
let foldhash_builder = foldhash::fast::RandomState::default();
255+
group.bench_function("foldhash::hash_one", |b| {
256+
b.iter(|| {
257+
for token in tokens {
258+
let t = black_box(*token);
259+
let _ = black_box(foldhash_builder.hash_one(t));
260+
}
261+
})
262+
});
263+
print_collision_rate(&unique_tokens, |t| foldhash_builder.hash_one(t));
264+
}
265+
250266
// Benchmark: CRC32
251267
if should_run("stateless/crc32fast::hash") {
252268
group.bench_function("crc32fast::hash", |b| {
@@ -362,6 +378,20 @@ fn bench_stateful(
362378
});
363379
}
364380

381+
// Benchmark: FoldHash
382+
if should_run("stateful/foldhash::FoldHasher") {
383+
group.bench_function("foldhash::FoldHasher", |b| {
384+
let state = foldhash::fast::RandomState::default();
385+
b.iter(|| {
386+
let mut aggregate = state.build_hasher();
387+
for token in tokens {
388+
aggregate.write(token);
389+
}
390+
black_box(aggregate.finish());
391+
})
392+
});
393+
}
394+
365395
// Benchmark: CRC32
366396
if should_run("stateful/crc32fast::Hasher") {
367397
group.bench_function("crc32fast::Hasher", |b| {

0 commit comments

Comments
 (0)