Skip to content

Commit

Permalink
Merge #55
Browse files Browse the repository at this point in the history
55: Even more benches r=crepererum a=crepererum



Co-authored-by: Marco Neumann <[email protected]>
  • Loading branch information
bors[bot] and crepererum committed Dec 12, 2018
2 parents f07449f + 2b75bb6 commit be8a858
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ script:
- cargo build --verbose --all
- cargo test --verbose --all
- cargo doc --verbose --all
- cargo bench --verbose --all --no-run
- cargo bench --verbose --all -- --test
branches:
only:
# This is where pull requests from "bors r+" are built.
Expand Down
43 changes: 41 additions & 2 deletions benches/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use pdatastructs::filters::bloomfilter::BloomFilter;
use pdatastructs::filters::cuckoofilter::CuckooFilter;
use pdatastructs::filters::quotientfilter::QuotientFilter;
use pdatastructs::filters::Filter;
use pdatastructs::rand::{ChaChaRng, SeedableRng};
use pdatastructs::rand::SeedableRng;
use rand_chacha::ChaChaRng;

fn setup_bloomfilter() -> BloomFilter<u64> {
let false_positive_rate = 0.02; // = 2%
Expand Down Expand Up @@ -54,6 +55,21 @@ where
})
}

fn run_query_single<F, S>(setup: S, b: &mut Bencher, n: u64)
where
S: Fn() -> F,
F: Filter<u64>,
{
let setup_and_fill = || {
let mut filter = setup();
for i in 0..n {
filter.insert(&i).unwrap();
}
filter
};
b.iter_with_setup(setup_and_fill, |filter| filter.query(&0))
}

fn benchmarks_setup(c: &mut Criterion) {
let functions = vec![
Fun::new("bloomfilter", |b, _| run_setup(setup_bloomfilter, b)),
Expand Down Expand Up @@ -82,5 +98,28 @@ fn benchmarks_insert_many(c: &mut Criterion) {
c.bench("insert_many", benchmark);
}

criterion_group!(benches, benchmarks_setup, benchmarks_insert_many,);
fn benchmarks_query_single(c: &mut Criterion) {
let parameters = vec![4_000, 8_000];
let benchmark = ParameterizedBenchmark::new(
"bloomfilter",
|b, n| run_query_single(setup_bloomfilter, b, *n),
parameters,
)
.with_function("cuckoofilter", |b, n| {
run_query_single(setup_cuckoofilter, b, *n)
})
.with_function("hashset", |b, n| run_query_single(setup_hashset, b, *n))
.with_function("quotientfilter", |b, n| {
run_query_single(setup_quotientfilter, b, *n)
})
.sample_size(20);
c.bench("query_single", benchmark);
}

criterion_group!(
benches,
benchmarks_setup,
benchmarks_insert_many,
benchmarks_query_single,
);
criterion_main!(benches);
5 changes: 3 additions & 2 deletions src/filters/compat.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
//! Implementation of `Filter` for certain non-probabilistic data structures. This can be helpful
//! for debugging and performance comparisons.
use std::collections::HashSet;
use std::hash::Hash;
use std::hash::{BuildHasher, Hash};

use void::Void;

use crate::filters::Filter;

impl<T> Filter<T> for HashSet<T>
impl<T, S> Filter<T> for HashSet<T, S>
where
T: Clone + Eq + Hash,
S: BuildHasher,
{
type InsertErr = Void;

Expand Down
2 changes: 1 addition & 1 deletion src/hyperloglog_data.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(feature = "cargo-clippy", allow(clippy::unreadable_literal))]
#![allow(clippy::unreadable_literal)]


pub const THRESHOLD_DATA_OFFSET: usize = 4;
Expand Down

0 comments on commit be8a858

Please sign in to comment.