diff --git a/afl/Cargo.toml b/afl/Cargo.toml index 89b498d3fa..c336e28efc 100644 --- a/afl/Cargo.toml +++ b/afl/Cargo.toml @@ -8,11 +8,20 @@ edition = "2018" [dev-dependencies] criterion = "0.3" # Benchmarking +xxhash-rust = { version = "0.8.0-beta.5", features = ["const_xxh3", "xxh3"] } # xxh3 hashing for rust +ahash = "0.6.1" # another hash +fxhash = "0.2.1" # yet another hash [[bench]] name = "rand_speeds" harness = false +[[bench]] +name = "hash_speeds" +harness = false + + + [features] default = ["std"] std = [] @@ -21,7 +30,7 @@ std = [] hashbrown = { version = "0.9", features = ["serde"] } # A faster hashmap, nostd compatible libc = "0.2" # For (*nix) libc num = "*" -xxhash-rust = { version = "0.8.0-beta.5", features = ["const_xxh3"] } # xxh3 hashing for rust +xxhash-rust = { version = "0.8.0-beta.5", features = ["xxh3"] } # xxh3 hashing for rust serde = { version = "1.0", default-features = false, features = ["alloc"] } # serialization lib typetag = "0.1" postcard = "0.5.1" # no_std compatible serde serialization fromat \ No newline at end of file diff --git a/afl/benches/hash_speeds.rs b/afl/benches/hash_speeds.rs new file mode 100644 index 0000000000..8e6d4734ba --- /dev/null +++ b/afl/benches/hash_speeds.rs @@ -0,0 +1,38 @@ +//! Compare the speed of rust hash implementations + +use ahash; +use fxhash; +use std::hash::Hasher; +use xxhash_rust::const_xxh3; +use xxhash_rust::xxh3; + +use afl::utils::{Rand, StdRand}; +use criterion::{black_box, criterion_group, criterion_main, Criterion}; + +fn criterion_benchmark(c: &mut Criterion) { + let mut rand = StdRand::new(0); + let mut bench_vec: Vec = vec![]; + for _ in 0..2 << 16 { + bench_vec.push(rand.below(256) as u8); + } + + c.bench_function("xxh3", |b| { + b.iter(|| xxh3::xxh3_64_with_seed(black_box(&bench_vec), 0)) + }); + c.bench_function("const_xxh3", |b| { + b.iter(|| const_xxh3::xxh3_64_with_seed(black_box(&bench_vec), 0)) + }); + c.bench_function("ahash", |b| { + b.iter(|| { + let mut hasher = ahash::AHasher::new_with_keys(123, 456); + hasher.write(black_box(&bench_vec)); + hasher.finish(); + }) + }); + c.bench_function("fxhash", |b| { + b.iter(|| fxhash::hash64(black_box(&bench_vec))) + }); +} + +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches); diff --git a/afl/benches/rand_speeds.rs b/afl/benches/rand_speeds.rs index 67c6ac7d10..087738659f 100644 --- a/afl/benches/rand_speeds.rs +++ b/afl/benches/rand_speeds.rs @@ -1,3 +1,5 @@ +//! Compare the speed of rand implementations + use afl::utils::{Rand, XorShift64Rand, Xoshiro256StarRand}; use criterion::{black_box, criterion_group, criterion_main, Criterion}; diff --git a/afl/src/utils.rs b/afl/src/utils.rs index 7ae75d2d76..9ee7ffb559 100644 --- a/afl/src/utils.rs +++ b/afl/src/utils.rs @@ -303,7 +303,7 @@ pub const fn next_pow2(val: u64) -> u64 { #[cfg(test)] mod tests { - use xxhash_rust::const_xxh3::xxh3_64_with_seed; + use xxhash_rust::xxh3::xxh3_64_with_seed; use crate::utils::{next_pow2, Rand, StdRand}; @@ -339,9 +339,5 @@ mod tests { assert_eq!(next_pow2(1000), 1024); assert_eq!(next_pow2(0xFFFFFFFF as u64), (0xFFFFFFFF as u64) + 1); } - - #[test] - fn test_xxh3_hash() { - assert_eq!(xxh3_64_with_seed(b"test", 0), 0); - } + }