Skip to content

Commit

Permalink
perf: Add extra benchmarks, always inline secrets methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluefinger committed Apr 17, 2024
1 parent 9b57128 commit c48588e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
37 changes: 36 additions & 1 deletion benches/rand_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn wyrand_benchmark(c: &mut Criterion) {

#[cfg(feature = "wyhash")]
fn wyhash_benchmark(c: &mut Criterion) {
use std::hash::Hasher;
use std::hash::{Hash, Hasher};

use criterion::BenchmarkId;
use wyrand::WyHash;
Expand Down Expand Up @@ -67,6 +67,41 @@ fn wyhash_benchmark(c: &mut Criterion) {
);
});

c.bench_function("Hash integer single", |b| {
b.iter(|| {
let mut hasher = WyHash::new_with_default_secret(black_box(42));

hasher.write_u64(black_box(256));

hasher.finish()
});
});

c.bench_function("Hash integer multiple", |b| {
let big_value = u64::MAX as u128 + 125;

b.iter(|| {
let mut hasher = WyHash::new_with_default_secret(black_box(42));

hasher.write_u64(black_box(256));
hasher.write_u128(black_box(big_value));

hasher.finish()
});
});

c.bench_function("Hash integer tuple", |b| {
let big_value = u64::MAX as u128 + 125;

b.iter(|| {
let mut hasher = WyHash::new_with_default_secret(black_box(42));

(black_box(42), black_box(big_value)).hash(&mut hasher);

hasher.finish()
});
});

c.bench_function("Hash new with default secret", |b| {
b.iter(|| WyHash::new_with_default_secret(black_box(42)));
});
Expand Down
8 changes: 4 additions & 4 deletions src/final_v4_2/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ impl Secret {
Self([first, second, third, fourth])
}

#[inline]
#[inline(always)]
pub(super) const fn first(&self) -> u64 {
self.0[0]
}

#[inline]
#[inline(always)]
pub(super) const fn second(&self) -> u64 {
self.0[1]
}

#[inline]
#[inline(always)]
pub(super) const fn third(&self) -> u64 {
self.0[2]
}

#[inline]
#[inline(always)]
pub(super) const fn fourth(&self) -> u64 {
self.0[3]
}
Expand Down
8 changes: 4 additions & 4 deletions src/legacy_final_v4/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ impl LegacySecret {
Self([first, second, third, fourth])
}

#[inline]
#[inline(always)]
pub(super) const fn first(&self) -> u64 {
self.0[0]
}

#[inline]
#[inline(always)]
pub(super) const fn second(&self) -> u64 {
self.0[1]
}

#[inline]
#[inline(always)]
pub(super) const fn third(&self) -> u64 {
self.0[2]
}

#[inline]
#[inline(always)]
pub(super) const fn fourth(&self) -> u64 {
self.0[3]
}
Expand Down

0 comments on commit c48588e

Please sign in to comment.