Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Moe manual backporting from #10999
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdplm committed Nov 8, 2019
1 parent 09fbadd commit bf55f37
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions util/blooms-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ parking_lot = "0.7"
tiny-keccak = "1.4"

[dev-dependencies]
criterion = "0.3.0"
tempdir = "0.3"
48 changes: 29 additions & 19 deletions util/blooms-db/benches/blooms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,27 @@
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.

#![feature(test)]

extern crate test;
#[macro_use]
extern crate criterion;
extern crate tempdir;
extern crate blooms_db;
extern crate ethbloom;

use std::iter;
use test::Bencher;
use criterion::Criterion;
use tempdir::TempDir;
use blooms_db::Database;
use ethbloom::Bloom;

#[bench]
fn blooms_filter_1_million_ok(b: &mut Bencher) {
criterion_group!(
blooms,
bench_blooms_filter_1_million_ok,
bench_blooms_filter_1_million_miss,
bench_blooms_filter_1_million_miss_and_ok,
);
criterion_main!(blooms);

fn bench_blooms_filter_1_million_ok(c: &mut Criterion) {
let tempdir = TempDir::new("").unwrap();
let database = Database::open(tempdir.path()).unwrap();
database.insert_blooms(999_999, iter::once(&Bloom::zero())).unwrap();
Expand All @@ -38,14 +44,15 @@ fn blooms_filter_1_million_ok(b: &mut Bencher) {
database.insert_blooms(600_000, iter::once(&bloom)).unwrap();
database.insert_blooms(800_000, iter::once(&bloom)).unwrap();

b.iter(|| {
let matches = database.filter(0, 999_999, Some(&bloom)).unwrap();
assert_eq!(matches, vec![200_000, 400_000, 600_000, 800_000]);
c.bench_function("blooms_filter_1_million_ok", move |b| {
b.iter(|| {
let matches = database.filter(0, 999_999, Some(&bloom)).unwrap();
assert_eq!(matches, vec![200_000, 400_000, 600_000, 800_000]);
})
});
}

#[bench]
fn blooms_filter_1_million_miss(b: &mut Bencher) {
fn bench_blooms_filter_1_million_miss(c: &mut Criterion) {
let tempdir = TempDir::new("").unwrap();
let database = Database::open(tempdir.path()).unwrap();
database.insert_blooms(999_999, iter::once(&Bloom::zero())).unwrap();
Expand All @@ -56,14 +63,15 @@ fn blooms_filter_1_million_miss(b: &mut Bencher) {
database.insert_blooms(600_000, iter::once(&bloom)).unwrap();
database.insert_blooms(800_000, iter::once(&bloom)).unwrap();

b.iter(|| {
let matches = database.filter(0, 999_999, Some(&bad_bloom)).unwrap();
assert_eq!(matches, vec![200_000, 400_000, 600_000, 800_000]);
c.bench_function("blooms_filter_1_million_miss", move |b| {
b.iter(|| {
let matches = database.filter(0, 999_999, Some(&bad_bloom)).unwrap();
assert_eq!(matches, vec![200_000, 400_000, 600_000, 800_000]);
})
});
}

#[bench]
fn blooms_filter_1_million_miss_and_ok(b: &mut Bencher) {
fn bench_blooms_filter_1_million_miss_and_ok(c: &mut Criterion) {
let tempdir = TempDir::new("").unwrap();
let database = Database::open(tempdir.path()).unwrap();
database.insert_blooms(999_999, iter::once(&Bloom::zero())).unwrap();
Expand All @@ -74,8 +82,10 @@ fn blooms_filter_1_million_miss_and_ok(b: &mut Bencher) {
database.insert_blooms(600_000, iter::once(&bloom)).unwrap();
database.insert_blooms(800_000, iter::once(&bloom)).unwrap();

b.iter(|| {
let matches = database.filter(0, 999_999, &vec![bad_bloom, bloom]).unwrap();
assert_eq!(matches, vec![200_000, 400_000, 600_000, 800_000]);
c.bench_function("blooms_filter_1_million_miss_and_ok", move |b| {
b.iter(|| {
let matches = database.filter(0, 999_999, &vec![bad_bloom, bloom]).unwrap();
assert_eq!(matches, vec![200_000, 400_000, 600_000, 800_000]);
})
});
}

0 comments on commit bf55f37

Please sign in to comment.