-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The AVX2 backend was previously computing two ChaCha blocks in parallel, then throwing one away. This updates the implementation to always compute two blocks in parallel when the AVX2 backend is enabled, resulting in a ~2X speedup. Unfortunately for `cipher.rs`, originally adapted from the `ctr` crate, I deleted the original parallel computation code, and in lieu of that the implementation diverges from what was originally in `ctr`. See here for a reference: https://github.com/RustCrypto/stream-ciphers/blob/907e94b/ctr/src/lib.rs#L73 Ideally we can come up with some generic counter management and buffering abstraction in the `ctr` crate which works in all cases.
- Loading branch information
Showing
10 changed files
with
130 additions
and
49 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//! `ChaCha20Rng` benchmark | ||
#[cfg(not(feature = "rng"))] | ||
compile_error!("run benchmarks with `cargo bench --all-features`"); | ||
|
||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; | ||
use criterion_cycles_per_byte::CyclesPerByte; | ||
|
||
use chacha20::ChaCha20Rng; | ||
use rand_core::{RngCore, SeedableRng}; | ||
|
||
const KB: usize = 1024; | ||
|
||
fn bench(c: &mut Criterion<CyclesPerByte>) { | ||
let mut group = c.benchmark_group("rng"); | ||
|
||
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 mut rng = ChaCha20Rng::from_seed(Default::default()); | ||
b.iter(|| rng.fill_bytes(&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
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
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