Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chacha20: Use criterion for benchmarking
...with the `criterion-cycles-per-byte` plugin This unfortunately means we can no-longer run tests for chacha20 against Rust 1.27.0, since it adds 2018 edition `dev-dependencies`. However, we can still confirm release builds against this version work. As we're starting to reach a microoptimization stage, I think criterion will be extremely helpful in determining if our microoptimizations are actually improving performance. Currently I'm getting between 5.1 - 5.8 cpb across the tests on a Kaby Lake i7. Curiously `-Ctarget-cpu=native` seems to negatively impact performance. I'm not seeing much difference between the software and SSE2 backends: +5% on the `chacha20/apply_keystream/1024` benchmark, negligable on the others (i.e. +1-2%)
- Loading branch information
Showing
4 changed files
with
66 additions
and
21 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
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 |
---|---|---|
@@ -1,6 +1,37 @@ | ||
#![feature(test)] | ||
#[macro_use] | ||
extern crate stream_cipher; | ||
extern crate chacha20; | ||
extern crate criterion; | ||
extern crate criterion_cycles_per_byte; | ||
|
||
bench_sync!(chacha20::ChaCha20); | ||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; | ||
use criterion_cycles_per_byte::CyclesPerByte; | ||
|
||
use chacha20::{ChaCha20, stream_cipher::{NewStreamCipher, SyncStreamCipher}}; | ||
|
||
const KB: usize = 1024; | ||
|
||
fn bench(c: &mut Criterion<CyclesPerByte>) { | ||
let mut group = c.benchmark_group("chacha20"); | ||
|
||
for size in &[KB, 2 * KB, 4 * KB, 8 * KB, 16 * KB] { | ||
let mut buf = vec![0u8; *size]; | ||
|
||
group.throughput(Throughput::Bytes(*size as u64)); | ||
|
||
group.bench_function(BenchmarkId::new("apply_keystream", size), |b| { | ||
let key = Default::default(); | ||
let nonce = Default::default(); | ||
let mut cipher = ChaCha20::new(&key, &nonce); | ||
|
||
b.iter(|| cipher.apply_keystream(&mut buf)); | ||
}); | ||
} | ||
|
||
group.finish(); | ||
} | ||
|
||
criterion_group!( | ||
name = benches; | ||
config = Criterion::default().with_measurement(CyclesPerByte); | ||
targets = bench | ||
); | ||
criterion_main!(benches); |
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 |
---|---|---|
@@ -1 +1 @@ | ||
RUSTFLAGS="-C target-feature=+aes,+sse2,+ssse3" RUSTDOCFLAGS=$RUSTFLAGS cargo test --all | ||
RUSTFLAGS="-C target-feature=+aes,+sse2,+ssse3" RUSTDOCFLAGS=$RUSTFLAGS cargo test --all --exclude chacha20 |