Skip to content

Commit 589cebc

Browse files
committed
hashes: Add bench for sha3_256
Following up on the addition of the SHA3-256 hash, it may be worthwhile to strive for improvements. In my runs of the benchmark, small slices perform poorly, indicating to me there may be something wrong with the padding. As input size increases the hash is on the order of the slower hashes in the library, which is acceptable for the use case. Those that want to try to improve the hash will need this bench.
1 parent c2cce97 commit 589cebc

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

hashes/src/sha3_256/benches.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use test::Bencher;
2+
3+
use crate::{Hash, HashEngine};
4+
5+
#[bench]
6+
pub fn sha3_256_10(bh: &mut Bencher) {
7+
let mut engine = crate::sha3_256::Hash::engine();
8+
let bytes = [1u8; 10];
9+
bh.iter(|| {
10+
engine.input(&bytes);
11+
});
12+
bh.bytes = bytes.len() as u64;
13+
}
14+
15+
#[bench]
16+
pub fn sha3_256_1k(bh: &mut Bencher) {
17+
let mut engine = crate::sha3_256::Hash::engine();
18+
let bytes = [1u8; 1024];
19+
bh.iter(|| {
20+
engine.input(&bytes);
21+
});
22+
bh.bytes = bytes.len() as u64;
23+
}
24+
25+
#[bench]
26+
pub fn sha3_256_64k(bh: &mut Bencher) {
27+
let mut engine = crate::sha3_256::Hash::engine();
28+
let bytes = [1u8; 65536];
29+
bh.iter(|| {
30+
engine.input(&bytes);
31+
});
32+
bh.bytes = bytes.len() as u64;
33+
}

hashes/src/sha3_256/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
//
1818
// To read this file, follow the example code: https://keccak.team/keccak_specs_summary.html
1919
// For a detailed specification: https://keccak.team/files/Keccak-reference-3.0.pdf
20+
#[cfg(bench)]
21+
mod benches;
2022
use core::fmt;
2123

2224
crate::internal_macros::general_hash_type! {

0 commit comments

Comments
 (0)