From 338f7db3a8a59f4abd6b074a7e6d022f34827bc3 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Fri, 10 Apr 2020 21:23:27 +0200 Subject: [PATCH 1/2] keccak-hash: fix bench and add one for range --- .travis.yml | 2 +- keccak-hash/Cargo.toml | 4 ++++ keccak-hash/benches/keccak_256.rs | 20 ++++++++++++++------ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 19c6b18ef..53e552f6d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,7 +40,7 @@ script: cargo fmt -- --check; fi - cargo check --workspace --tests --benches - - cargo test --all --exclude uint --exclude fixed-hash --exclude parity-crypto + - cargo test --workspace --exclude uint --exclude fixed-hash --exclude parity-crypto - if [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then cd contract-address/ && cargo test --features=external_doc && cd ..; fi diff --git a/keccak-hash/Cargo.toml b/keccak-hash/Cargo.toml index 54c1c0439..c663c66c5 100644 --- a/keccak-hash/Cargo.toml +++ b/keccak-hash/Cargo.toml @@ -19,3 +19,7 @@ criterion = "0.3.0" [features] default = ["std"] std = [] + +[[bench]] +name = "keccak_256" +harness = false diff --git a/keccak-hash/benches/keccak_256.rs b/keccak-hash/benches/keccak_256.rs index 97e9ee13d..4a883540a 100644 --- a/keccak-hash/benches/keccak_256.rs +++ b/keccak-hash/benches/keccak_256.rs @@ -22,12 +22,20 @@ pub fn keccak_256_with_empty_input(c: &mut Criterion) { } pub fn keccak_256_with_typical_input(c: &mut Criterion) { - let data: Vec = From::from("some medium length string with important information"); - c.bench_function("keccak_256_with_typical_input", |b| { - b.iter(|| { - let _out = keccak(black_box(&data)); - }) - }); + let mut data: Vec = From::from("some medium length string with important information"); + let len = data.len(); + let mut group = c.benchmark_group("keccak_256_with_typical_input"); + group.bench_function("regular", |b| b.iter(|| { + let _out = keccak(black_box(&data)); + })); + group.bench_function("inplace", |b| b.iter(|| { + keccak_hash::keccak256(black_box(&mut data[..])); + })); + group.bench_function("inplace_range", |b| b.iter(|| { + keccak_hash::keccak256_range(black_box(&mut data[..]), 0..len); + })); + + group.finish(); } pub fn keccak_256_with_large_input(c: &mut Criterion) { From e7fca206bcc54e3cbb56a0854db1367ca1143438 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Fri, 10 Apr 2020 22:04:20 +0200 Subject: [PATCH 2/2] fmt --- keccak-hash/benches/keccak_256.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/keccak-hash/benches/keccak_256.rs b/keccak-hash/benches/keccak_256.rs index 4a883540a..3a28f993a 100644 --- a/keccak-hash/benches/keccak_256.rs +++ b/keccak-hash/benches/keccak_256.rs @@ -25,15 +25,21 @@ pub fn keccak_256_with_typical_input(c: &mut Criterion) { let mut data: Vec = From::from("some medium length string with important information"); let len = data.len(); let mut group = c.benchmark_group("keccak_256_with_typical_input"); - group.bench_function("regular", |b| b.iter(|| { - let _out = keccak(black_box(&data)); - })); - group.bench_function("inplace", |b| b.iter(|| { - keccak_hash::keccak256(black_box(&mut data[..])); - })); - group.bench_function("inplace_range", |b| b.iter(|| { - keccak_hash::keccak256_range(black_box(&mut data[..]), 0..len); - })); + group.bench_function("regular", |b| { + b.iter(|| { + let _out = keccak(black_box(&data)); + }) + }); + group.bench_function("inplace", |b| { + b.iter(|| { + keccak_hash::keccak256(black_box(&mut data[..])); + }) + }); + group.bench_function("inplace_range", |b| { + b.iter(|| { + keccak_hash::keccak256_range(black_box(&mut data[..]), 0..len); + }) + }); group.finish(); }