Skip to content

Commit

Permalink
keccak-hash: fix bench and add one for range (#372)
Browse files Browse the repository at this point in the history
* keccak-hash: fix bench and add one for range

* fmt
  • Loading branch information
ordian authored Apr 11, 2020
1 parent 13ae5be commit 0bba566
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions keccak-hash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ criterion = "0.3.0"
[features]
default = ["std"]
std = []

[[bench]]
name = "keccak_256"
harness = false
18 changes: 16 additions & 2 deletions keccak-hash/benches/keccak_256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,26 @@ pub fn keccak_256_with_empty_input(c: &mut Criterion) {
}

pub fn keccak_256_with_typical_input(c: &mut Criterion) {
let data: Vec<u8> = From::from("some medium length string with important information");
c.bench_function("keccak_256_with_typical_input", |b| {
let mut data: Vec<u8> = 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) {
Expand Down

0 comments on commit 0bba566

Please sign in to comment.