From bf55f37c0ae7d37f3d89ac56d04f3e10e5a54be2 Mon Sep 17 00:00:00 2001 From: David Palm Date: Fri, 8 Nov 2019 17:58:10 +0100 Subject: [PATCH] Moe manual backporting from https://github.com/paritytech/parity-ethereum/pull/10999 --- Cargo.lock | 1 + util/blooms-db/Cargo.toml | 1 + util/blooms-db/benches/blooms.rs | 48 +++++++++++++++++++------------- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f8f2bcff281..62cd911d499 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -248,6 +248,7 @@ name = "blooms-db" version = "0.1.0" dependencies = [ "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "criterion 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethbloom 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/util/blooms-db/Cargo.toml b/util/blooms-db/Cargo.toml index 0889184db63..543a7987725 100644 --- a/util/blooms-db/Cargo.toml +++ b/util/blooms-db/Cargo.toml @@ -11,4 +11,5 @@ parking_lot = "0.7" tiny-keccak = "1.4" [dev-dependencies] +criterion = "0.3.0" tempdir = "0.3" diff --git a/util/blooms-db/benches/blooms.rs b/util/blooms-db/benches/blooms.rs index 4b07f3d5a6e..190caca99ba 100644 --- a/util/blooms-db/benches/blooms.rs +++ b/util/blooms-db/benches/blooms.rs @@ -14,21 +14,27 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -#![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(); @@ -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(); @@ -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(); @@ -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]); + }) }); }