added hash speed benchmark
This commit is contained in:
parent
0cda3792d1
commit
83a05049bf
@ -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
|
38
afl/benches/hash_speeds.rs
Normal file
38
afl/benches/hash_speeds.rs
Normal file
@ -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<u8> = 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);
|
@ -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};
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user