forked from rust-bitcoin/rust-bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge rust-bitcoin#4071: chacha20: add benchmarks
e41653d add chacha20 benchmarks (jeremiah) Pull request description: Add benchmarks for chacha20. These could be useful to understand future improvements. I copied the same 10, 1k and 64k sizes as used in the sha256 benchmark. Some of the lines changed here, such as in `Config.toml`, are a little mysterious to me as I am new to rust, so please check. ``` ➜ chacha20_poly1305 git:(jr_chachabench) RUSTFLAGS='--cfg=bench' cargo +nightly bench ... test benches::chacha20_10 ... bench: 188.67 ns/iter (+/- 2.70) = 53 MB/s test benches::chacha20_1k ... bench: 2,885.83 ns/iter (+/- 90.06) = 354 MB/s test benches::chacha20_64k ... bench: 186,493.88 ns/iter (+/- 5,074.53) = 351 MB/s ``` ACKs for top commit: apoelstra: ACK e41653d; successfully ran local tests; nice! Kixunil: ACK e41653d Tree-SHA512: fa37a4b6842ab78edc32726b22410d9769c1f03e1bc3488517e1e59e17388cabb63e58eb6ea6f112cb27ff1015296f356275ddee12d261c848050e98e3c6eed6
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use test::Bencher; | ||
|
||
use crate::{ChaCha20, Key, Nonce}; | ||
|
||
#[bench] | ||
pub fn chacha20_10(bh: &mut Bencher) { | ||
let key = | ||
Key::new([0u8; 32]); | ||
let nonce = Nonce::new([0u8; 12]); | ||
let count = 1; | ||
let mut chacha = ChaCha20::new(key, nonce, count); | ||
let mut bytes = [0u8; 10]; | ||
bh.iter(|| { | ||
chacha.apply_keystream(&mut bytes[..]); | ||
}); | ||
bh.bytes = bytes.len() as u64; | ||
} | ||
|
||
#[bench] | ||
pub fn chacha20_1k(bh: &mut Bencher) { | ||
let key = | ||
Key::new([0u8; 32]); | ||
let nonce = Nonce::new([0u8; 12]); | ||
let count = 1; | ||
let mut chacha = ChaCha20::new(key, nonce, count); | ||
let mut bytes = [0u8; 1024]; | ||
bh.iter(|| { | ||
chacha.apply_keystream(&mut bytes[..]); | ||
}); | ||
bh.bytes = bytes.len() as u64; | ||
} | ||
|
||
#[bench] | ||
pub fn chacha20_64k(bh: &mut Bencher) { | ||
let key = | ||
Key::new([0u8; 32]); | ||
let nonce = Nonce::new([0u8; 12]); | ||
let count = 1; | ||
let mut chacha = ChaCha20::new(key, nonce, count); | ||
let mut bytes = [0u8; 65536]; | ||
bh.iter(|| { | ||
chacha.apply_keystream(&mut bytes[..]); | ||
}); | ||
bh.bytes = bytes.len() as u64; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters