From eecc2d2b842770ae79c9a0e635028fe65daa1b7f Mon Sep 17 00:00:00 2001 From: Marco Neumann Date: Sat, 25 Aug 2018 17:59:35 +0200 Subject: [PATCH 1/2] topk: fix example --- src/topk.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/topk.rs b/src/topk.rs index 760557a..a01cb4a 100644 --- a/src/topk.rs +++ b/src/topk.rs @@ -84,12 +84,12 @@ where /// } else { /// x /// }; -/// tk.add(x); +/// tk.add(y); /// } /// /// // later /// let elements: Vec = tk.iter().collect(); -/// assert_eq!(elements, vec![0, 1]); +/// assert_eq!(elements, vec![1, 0]); /// ``` /// /// # Applications From 80a20875eb2c2ce73ab3fc55b02e25784b37e4c4 Mon Sep 17 00:00:00 2001 From: Marco Neumann Date: Sat, 25 Aug 2018 18:05:26 +0200 Subject: [PATCH 2/2] global: setup benchmarking system --- .travis.yml | 1 + Cargo.toml | 7 +++++++ benches/bloomfilter.rs | 22 ++++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 benches/bloomfilter.rs diff --git a/.travis.yml b/.travis.yml index c34f69a..dd3710d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ script: - cargo build --verbose --all - cargo test --verbose --all - cargo doc --verbose --all + - cargo bench --verbose --all branches: only: # This is where pull requests from "bors r+" are built. diff --git a/Cargo.toml b/Cargo.toml index 977f4c1..4b18803 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,3 +20,10 @@ bytecount = "0.3" fixedbitset = "^0.1.9" num-traits = "^0.2.4" rand = "0.5" + +[dev-dependencies] +criterion = "0.2" + +[[bench]] +name = "bloomfilter" +harness = false diff --git a/benches/bloomfilter.rs b/benches/bloomfilter.rs new file mode 100644 index 0000000..449a23a --- /dev/null +++ b/benches/bloomfilter.rs @@ -0,0 +1,22 @@ +#[macro_use] +extern crate criterion; +extern crate pdatastructs; + +use criterion::Criterion; +use pdatastructs::bloomfilter::BloomFilter; + +fn bloomfilter_add_single(c: &mut Criterion) { + c.bench_function("bloomfilter_add_single", |b| { + let false_positive_rate = 0.02; // = 2% + let expected_elements = 1000; + let mut filter = BloomFilter::with_properties(expected_elements, false_positive_rate); + let obj = "foo bar"; + + b.iter(|| { + filter.add(&obj); + }) + }); +} + +criterion_group!(benches, bloomfilter_add_single); +criterion_main!(benches);