From 1683e88aaf6525168441cdd72bec2c4513c5d678 Mon Sep 17 00:00:00 2001 From: koushiro Date: Wed, 4 Sep 2019 15:57:14 +0800 Subject: [PATCH 1/5] migrate plain_hasher to 2018 edition Signed-off-by: koushiro --- plain_hasher/Cargo.toml | 12 ++++++++-- plain_hasher/benches/bench.rs | 42 ++++++++++++++--------------------- plain_hasher/src/lib.rs | 12 ++++------ 3 files changed, 31 insertions(+), 35 deletions(-) diff --git a/plain_hasher/Cargo.toml b/plain_hasher/Cargo.toml index 9385afbd0..2228b4a91 100644 --- a/plain_hasher/Cargo.toml +++ b/plain_hasher/Cargo.toml @@ -6,11 +6,19 @@ authors = ["Parity Technologies "] license = "MIT" keywords = ["hash", "hasher"] homepage = "https://github.com/paritytech/parity-common" -categories = [ "no-std"] +categories = ["no-std"] +edition = "2018" [dependencies] -crunchy = { version = "0.2.1", default-features = false } +crunchy = { version = "0.2", default-features = false } + +[dev-dependencies] +criterion = "0.3" [features] default = ["std"] std = ["crunchy/std"] + +[[bench]] +name = "bench" +harness = false diff --git a/plain_hasher/benches/bench.rs b/plain_hasher/benches/bench.rs index cfaa95eaa..d5701ef87 100644 --- a/plain_hasher/benches/bench.rs +++ b/plain_hasher/benches/bench.rs @@ -14,36 +14,28 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -#![feature(test)] - -extern crate test; -extern crate plain_hasher; - -use std::hash::Hasher; use std::collections::hash_map::DefaultHasher; -use test::{Bencher, black_box}; +use std::hash::Hasher; + +use criterion::{criterion_group, criterion_main, Criterion}; use plain_hasher::PlainHasher; -#[bench] -fn write_plain_hasher(b: &mut Bencher) { - b.iter(|| { - let n: u8 = black_box(100); - (0..n).fold(PlainHasher::default(), |mut old, new| { - let bb = black_box([new; 32]); - old.write(&bb as &[u8]); +fn bench_write_hasher(c: &mut Criterion) { + c.bench_function("write_plain_hasher", |b| b.iter(|| { + (0..100u8).fold(PlainHasher::default(), |mut old, new| { + let bb = [new; 32]; + old.write(&bb); old }); - }); -} - -#[bench] -fn write_default_hasher(b: &mut Bencher) { - b.iter(|| { - let n: u8 = black_box(100); - (0..n).fold(DefaultHasher::default(), |mut old, new| { - let bb = black_box([new; 32]); - old.write(&bb as &[u8]); + })); + c.bench_function("write_default_hasher", |b| b.iter(|| { + (0..100u8).fold(DefaultHasher::default(), |mut old, new| { + let bb = [new; 32]; + old.write(&bb); old }); - }); + })); } + +criterion_group!(benches, bench_write_hasher); +criterion_main!(benches); diff --git a/plain_hasher/src/lib.rs b/plain_hasher/src/lib.rs index da574eb63..3665995d4 100644 --- a/plain_hasher/src/lib.rs +++ b/plain_hasher/src/lib.rs @@ -16,13 +16,10 @@ #![cfg_attr(not(feature = "std"), no_std)] -#[macro_use] -extern crate crunchy; +use core::hash::Hasher; -#[cfg(feature = "std")] -extern crate core; +use crunchy::unroll; -use core::hash; /// Hasher that just takes 8 bytes of the provided value. /// May only be used for keys which are 32 bytes. #[derive(Default)] @@ -30,7 +27,7 @@ pub struct PlainHasher { prefix: u64, } -impl hash::Hasher for PlainHasher { +impl Hasher for PlainHasher { #[inline] fn finish(&self) -> u64 { self.prefix @@ -57,8 +54,7 @@ impl hash::Hasher for PlainHasher { #[cfg(test)] mod tests { - use core::hash::Hasher; - use super::PlainHasher; + use super::*; #[test] fn it_works() { From 8d406b5ba7c8334a07495c529cf7832cb13039f8 Mon Sep 17 00:00:00 2001 From: koushiro Date: Wed, 4 Sep 2019 15:58:19 +0800 Subject: [PATCH 2/5] Update travis ci config Signed-off-by: koushiro --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9d5a42748..74b9e7641 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,7 +34,7 @@ script: fi - cd fixed-hash/ && cargo test --all-features && cd .. - cd uint/ && cargo test --features=std,quickcheck --release && cd .. - - cd plain_hasher/ && cargo test --no-default-features && cd .. + - cd plain_hasher/ && cargo test --no-default-features && cargo test --benches && cd .. - cd parity-util-mem/ && cargo test --features=estimate-heapsize && cd .. - cd parity-util-mem/ && cargo test --features=jemalloc-global && cd .. - cd parity-util-mem/ && cargo test --features=mimalloc-global && cd .. From 1edd4b66bff3c8b5ad15a3c2a1b9898d05fab8bb Mon Sep 17 00:00:00 2001 From: koushiro Date: Wed, 4 Sep 2019 17:01:20 +0800 Subject: [PATCH 3/5] Update travis ci config Signed-off-by: koushiro --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 74b9e7641..492a114e4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,7 +34,7 @@ script: fi - cd fixed-hash/ && cargo test --all-features && cd .. - cd uint/ && cargo test --features=std,quickcheck --release && cd .. - - cd plain_hasher/ && cargo test --no-default-features && cargo test --benches && cd .. + - cd plain_hasher/ && cargo test --no-default-features && cargo test --benches -- --bench && cd .. - cd parity-util-mem/ && cargo test --features=estimate-heapsize && cd .. - cd parity-util-mem/ && cargo test --features=jemalloc-global && cd .. - cd parity-util-mem/ && cargo test --features=mimalloc-global && cd .. From 08a3e54aad837d88d8659962f5e4a7d87e45db65 Mon Sep 17 00:00:00 2001 From: koushiro Date: Wed, 4 Sep 2019 18:14:21 +0800 Subject: [PATCH 4/5] Update travis ci config Signed-off-by: koushiro --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 492a114e4..74b9e7641 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,7 +34,7 @@ script: fi - cd fixed-hash/ && cargo test --all-features && cd .. - cd uint/ && cargo test --features=std,quickcheck --release && cd .. - - cd plain_hasher/ && cargo test --no-default-features && cargo test --benches -- --bench && cd .. + - cd plain_hasher/ && cargo test --no-default-features && cargo test --benches && cd .. - cd parity-util-mem/ && cargo test --features=estimate-heapsize && cd .. - cd parity-util-mem/ && cargo test --features=jemalloc-global && cd .. - cd parity-util-mem/ && cargo test --features=mimalloc-global && cd .. From 7a9d7921ac220ba3c532bd7dc5128cf76e4d7dd9 Mon Sep 17 00:00:00 2001 From: koushiro Date: Thu, 5 Sep 2019 15:19:59 +0800 Subject: [PATCH 5/5] Revert ci config Signed-off-by: koushiro --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8aefcbfb1..5386398af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,7 @@ script: fi - cd fixed-hash/ && cargo test --all-features && cd .. - cd uint/ && cargo test --features=std,quickcheck --release && cd .. - - cd plain_hasher/ && cargo test --no-default-features && cargo test --benches && cd .. + - cd plain_hasher/ && cargo test --no-default-features && cargo check --benches && cd .. - cd parity-bytes/ && cargo test --no-default-features && cd .. - cd parity-util-mem/ && cargo test --features=estimate-heapsize && cd .. - cd parity-util-mem/ && cargo test --features=jemalloc-global && cd ..