dependabot[bot] 4dc5a8ed14
Update criterion requirement from 0.5.1 to 0.6.0 (#3251)
* Update criterion requirement from 0.5.1 to 0.6.0

Updates the requirements on [criterion](https://github.com/bheisler/criterion.rs) to permit the latest version.
- [Changelog](https://github.com/bheisler/criterion.rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/bheisler/criterion.rs/compare/0.5.1...0.6.0)

---
updated-dependencies:
- dependency-name: criterion
  dependency-version: 0.6.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

* clippy

* undo / too modern

* clip

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Dominik Maier <dmnk@google.com>
2025-05-19 14:49:25 +02:00

45 lines
1.3 KiB
Rust

//! Compare the speed of rust hash implementations
use core::{
hash::{BuildHasher, Hasher},
hint::black_box,
num::NonZero,
};
use criterion::{Criterion, criterion_group, criterion_main};
use libafl_bolts::rands::{Rand, StdRand};
//use xxhash_rust::const_xxh3;
use xxhash_rust::xxh3;
fn criterion_benchmark(c: &mut Criterion) {
let mut rand = StdRand::with_seed(0);
let mut bench_vec: Vec<u8> = vec![];
for _ in 0..2 << 16 {
bench_vec.push(rand.below(NonZero::new(256).unwrap()) as u8);
}
c.bench_function("xxh3", |b| {
b.iter(|| black_box(xxh3::xxh3_64_with_seed(&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::RandomState::with_seeds(123, 456, 789, 123).build_hasher();
hasher.write(black_box(&bench_vec));
black_box(hasher.finish());
});
});
c.bench_function("fxhash", |b| {
b.iter(|| {
let mut hasher = rustc_hash::FxHasher::default();
hasher.write(black_box(&bench_vec));
black_box(hasher.finish());
});
});
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);