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

Add FxHash to bench #87

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ highway = "1.1.0"
seahash = "4.1.0"
metrohash = "1.0.6"
fnv = "1.0.3"
rustc-hash = "2.0.0"

[dev-dependencies.plotters]
version = "0.3.5"
Expand Down
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,56 @@ Throughput is measured as the number of bytes hashed per second.
![x86_64](./benches/throughput/x86_64.svg)
![x86_64-hybrid](./benches/throughput/x86_64-hybrid.svg)

### Quality

<details>
<summary>See quality benchmark results</summary>

#### GxHash

```
✅ avalanche::<B,4>()
✅ avalanche::<B,10>()
✅ avalanche::<B,32>()
✅ avalanche::<B,128>()
✅ avalanche::<B,512>()
✅ distribution_values::<B,4>(128*128)
✅ distribution_values::<B,16>(128*128)
✅ distribution_values::<B,128>(128*128)
✅ distribution_values::<B,512>(128*128)
✅ distribution_bits::<B,4>()
✅ distribution_bits::<B,16>()
✅ distribution_bits::<B,128>()
✅ distribution_bits::<B,512>()
✅ collisions_padded_zeroes::<B>(128*128)
✅ collisions_flipped_bits::<B,2>(9)
✅ collisions_flipped_bits::<B,3>(9)
✅ collisions_flipped_bits::<B,4>(7)
✅ collisions_flipped_bits::<B,5>(6)
✅ collisions_flipped_bits::<B,6>(5)
✅ collisions_flipped_bits::<B,7>(5)
✅ collisions_flipped_bits::<B,9>(4)
✅ collisions_flipped_bits::<B,20>(4)
✅ collisions_flipped_bits::<B,32>(3)
✅ collisions_flipped_bits::<B,64>(3)
✅ collisions_flipped_bits::<B,256>(2)
✅ collisions_permute::<B,u8>(4,&Vec::from_iter(0..16))
✅ collisions_permute::<B,u8>(42,&Vec::from_iter(0..64))
✅ collisions_permute::<B,u16>(42,&Vec::from_iter(0..64))
✅ collisions_permute::<B,u32>(42,&Vec::from_iter(0..64))
✅ collisions_permute::<B,u64>(42,&Vec::from_iter(0..64))
✅ collisions_permute::<B,u128>(4,&Vec::from_iter(0..16))
✅ collisions_permute::<B,u128>(42,&Vec::from_iter(0..64))
✅ collisions_powerset_bytes::<B>(&[0,1,2,3,4,5,6,7,8,9])
✅ collisions_powerset_bytes::<B>(&[0,1,2,4,8,16,32,64,128])
✅ hasher_collisions_permute::<B,u8>(&[0,1,2,3,4,5,6,7,8,9])
✅ hasher_collisions_permute::<B,u32>(&[0,1,2,3,4,5,6,7,8,9])
✅ hasher_collisions_permute::<B,u32>(&[0,1,2,4,8,16,32,64,128,256])
✅ hasher_collisions_powerset::<B,u32>(&[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19])
✅ hasher_collisions_powerset::<B,u32>(&[0,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384])
```
</details>

## Security

### DOS Resistance
Expand Down
5 changes: 3 additions & 2 deletions benches/quality/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use std::{hash::{Hash, Hasher, BuildHasher}, collections::HashSet, slice};
use std::{collections::HashSet, hash::{BuildHasher, BuildHasherDefault, Hash, Hasher}, slice};
use rand::Rng;
use criterion::black_box;

fn main() {
bench_hasher_quality::<gxhash::GxBuildHasher>("GxHash");
bench_hasher_quality::<ahash::RandomState>("AHash");
bench_hasher_quality::<t1ha::T1haBuildHasher>("T1ha");
bench_hasher_quality::<twox_hash::xxh3::RandomHashBuilder64>("XxHash3");
bench_hasher_quality::<twox_hash::xxh3::RandomHashBuilder64>("XxHash3 (twox_hash)");
bench_hasher_quality::<std::collections::hash_map::RandomState>("Default");
bench_hasher_quality::<BuildHasherDefault<rustc_hash::FxHasher>>("FxHasher (rustc_hash)");
bench_hasher_quality::<fnv::FnvBuildHasher>("FNV-1a");
}

Expand Down
133 changes: 72 additions & 61 deletions benches/throughput/aarch64.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions benches/throughput/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ fn main() {
twox_hash::xxh3::hash64_with_seed(data, seed)
});

// FxHash (rustc-hash)
benchmark(processor.as_mut(), slice, "fxhash", |data: &[u8], seed: u64| -> u64 {
let mut fxhasher = rustc_hash::FxHasher::default();
fxhasher.write_u64(seed); // Better way to seed?
fxhasher.write(data);
fxhasher.finish()
});

// AHash
let ahash_hasher = ahash::RandomState::with_seeds(0, 0, 0, 0);
benchmark(processor.as_mut(), slice, "ahash", |data: &[u8], _: i32| -> u64 {
Expand Down
Loading