Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
strategy:
matrix:
rust:
- "1.60.0"
- "1.65.0"
- "1.66.0"
- "1.76.0"
steps:
- uses: dtolnay/rust-toolchain@master
with:
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ harness = false
[features]
default = ["parallel"]
parallel = ["rayon", "crossbeam-utils"]

[profile.release]
lto = true
debug = 2
145 changes: 134 additions & 11 deletions benches/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,157 @@ extern crate bencher;

use bencher::Bencher;

use boomphf::Mphf;
use boomphf::{ExternallyHashed, Mphf};

fn build1_ser(bench: &mut Bencher) {
fn build1_ser_u64(bench: &mut Bencher) {
let items: Vec<u64> = (0..1000000u64).map(|x| x * 2).collect();
bench.iter(|| {
std::hint::black_box(Mphf::new(2.0, &items));
});
}

fn build1_ser_externally_hashed(bench: &mut Bencher) {
let items: Vec<ExternallyHashed> = (0..1000000u64)
.map(|x| ExternallyHashed(wyhash::wyrng(&mut (x * 2))))
.collect();
bench.iter(|| {
std::hint::black_box(Mphf::new(2.0, &items));
});
}

fn build1_ser_slices(bench: &mut Bencher) {
let items: Vec<[u8; 8]> = (0..1000000u64).map(|x| (x * 2).to_le_bytes()).collect();
bench.iter(|| {
std::hint::black_box(Mphf::new(2.0, &items));
});
}

fn build1_ser_long_slices(bench: &mut Bencher) {
let items = (0..1000000u64)
.map(|x| {
let mut long_key = [0u8; 128];
long_key[0..8].copy_from_slice(&(x * 2).to_le_bytes());
long_key
})
.collect::<Vec<_>>();
bench.iter(|| {
let items: Vec<u64> = (0..1000000u64).map(|x| x * 2).collect();
let _ = Mphf::new(2.0, &items);
std::hint::black_box(Mphf::new(2.0, &items));
});
}

fn build1_ser_long_slices_externally_hashed(bench: &mut Bencher) {
let items = (0..1000000u64)
.map(|x| {
let mut long_key = [0u8; 128];
long_key[0..8].copy_from_slice(&(x * 2).to_le_bytes());
ExternallyHashed(wyhash::wyhash(&long_key, 0))
})
.collect::<Vec<_>>();
bench.iter(|| {
std::hint::black_box(Mphf::new(2.0, &items));
});
}

#[allow(dead_code)]
fn build1_par(bench: &mut Bencher) {
fn build1_par_u64(bench: &mut Bencher) {
let items: Vec<u64> = (0..1000000u64).map(|x| x * 2).collect();
#[cfg(feature = "parallel")]
bench.iter(|| {
let items: Vec<u64> = (0..1000000u64).map(|x| x * 2).collect();
let _ = Mphf::new_parallel(2.0, &items, None);
std::hint::black_box(Mphf::new_parallel(2.0, &items, None));
});
}

fn scan1_ser(bench: &mut Bencher) {
#[allow(dead_code)]
fn build1_par_slices(bench: &mut Bencher) {
let items: Vec<[u8; 8]> = (0..1000000u64).map(|x| (x * 2).to_le_bytes()).collect();
#[cfg(feature = "parallel")]
bench.iter(|| {
std::hint::black_box(Mphf::new_parallel(2.0, &items, None));
});
}

fn scan1_ser_u64(bench: &mut Bencher) {
let items: Vec<u64> = (0..1000000u64).map(|x| x * 2).collect();
let phf = Mphf::new(2.0, &items);

bench.iter(|| {
for i in (0..1000000u64).map(|x| x * 2) {
phf.hash(&i);
for i in &items {
std::hint::black_box(phf.hash(&i));
}
});
}

fn scan1_ser_slice(bench: &mut Bencher) {
let items: Vec<[u8; 8]> = (0..1000000u64).map(|x| (x * 2).to_le_bytes()).collect();
let phf = Mphf::new(2.0, &items);

bench.iter(|| {
for i in &items {
std::hint::black_box(phf.hash(i));
}
});
}

fn scan1_ser_externally_hashed(bench: &mut Bencher) {
let items: Vec<ExternallyHashed> = (0..1000000u64)
.map(|x| ExternallyHashed(wyhash::wyrng(&mut (x * 2))))
.collect();
let phf = Mphf::new(2.0, &items);

bench.iter(|| {
for i in &items {
std::hint::black_box(phf.hash(i));
}
});
}

fn scan1_ser_long_key(bench: &mut Bencher) {
let items = (0..1000000u64)
.map(|x| {
let mut long_key = [0u8; 128];
long_key[0..8].copy_from_slice(&(x * 2).to_le_bytes());
long_key
})
.collect::<Vec<_>>();
let phf = Mphf::new(2.0, &items);

bench.iter(|| {
for i in &items {
std::hint::black_box(phf.hash(i));
}
});
}

fn scan1_ser_long_key_externally_hashed(bench: &mut Bencher) {
let items: Vec<ExternallyHashed> = (0..1000000u64)
.map(|x| {
let mut long_key = [0u8; 128];
long_key[0..8].copy_from_slice(&(x * 2).to_le_bytes());
ExternallyHashed(wyhash::wyhash(&long_key, 0))
})
.collect();
let phf = Mphf::new(2.0, &items);

bench.iter(|| {
for i in &items {
std::hint::black_box(phf.hash(i));
}
});
}

benchmark_group!(benches, build1_ser, build1_par, scan1_ser);
benchmark_group!(
benches,
build1_ser_externally_hashed,
build1_ser_u64,
build1_ser_slices,
build1_ser_long_slices,
build1_ser_long_slices_externally_hashed,
build1_par_u64,
build1_par_slices,
scan1_ser_u64,
scan1_ser_slice,
scan1_ser_externally_hashed,
scan1_ser_long_key,
scan1_ser_long_key_externally_hashed
);
benchmark_main!(benches);
2 changes: 1 addition & 1 deletion src/bitvector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ impl BitVector {
#[inline]
pub fn get_word(&self, word: usize) -> u64 {
#[cfg(feature = "parallel")]
return self.vector[word].load(Ordering::Relaxed) as u64;
return self.vector[word].load(Ordering::Relaxed);

#[cfg(not(feature = "parallel"))]
return self.vector[word] as u64;
Expand Down
Loading