Skip to content

Commit

Permalink
Merge pull request #72 from nvzqz/patch-1
Browse files Browse the repository at this point in the history
Use runtime arguments in Divan benchmarks
  • Loading branch information
codahale committed Jan 21, 2024
2 parents ba3e0e6 + fd34d73 commit ae8dd6e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ publish = false
edition = "2021"

[dependencies]
divan = "0.1.8"
divan = "0.1.11"
lockstitch = { path = ".." }

[[bench]]
Expand Down
32 changes: 16 additions & 16 deletions benchmarks/benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ use lockstitch::{Protocol, TAG_LEN};

const LENS: &[usize] = &[16, 256, 1024, 16 * 1024, 1024 * 1024];

#[divan::bench(consts = LENS)]
fn hash<const LEN: usize>(bencher: divan::Bencher) {
bencher.with_inputs(|| vec![0u8; LEN]).counter(BytesCount::new(LEN)).bench_refs(|message| {
#[divan::bench(args = LENS)]
fn hash(bencher: divan::Bencher, len: usize) {
bencher.with_inputs(|| vec![0u8; len]).counter(BytesCount::new(len)).bench_refs(|message| {
let mut protocol = Protocol::new("hash");
protocol.mix("message", message);
protocol.derive_array::<32>("digest")
});
}

#[divan::bench(consts = LENS)]
fn hash_writer<const LEN: usize>(bencher: divan::Bencher) {
#[divan::bench(args = LENS)]
fn hash_writer(bencher: divan::Bencher, len: usize) {
bencher
.with_inputs(|| io::repeat(0).take(LEN as u64))
.counter(BytesCount::new(LEN))
.with_inputs(|| io::repeat(0).take(len as u64))
.counter(BytesCount::new(len))
.bench_values(|mut input| {
let protocol = Protocol::new("hash");
let mut writer = protocol.mix_writer("message", io::sink());
Expand All @@ -30,11 +30,11 @@ fn hash_writer<const LEN: usize>(bencher: divan::Bencher) {
});
}

#[divan::bench(consts = LENS)]
fn stream<const LEN: usize>(bencher: divan::Bencher) {
#[divan::bench(args = LENS)]
fn stream(bencher: divan::Bencher, len: usize) {
let key = [0u8; 32];
let nonce = [0u8; 16];
bencher.with_inputs(|| vec![0u8; LEN]).counter(BytesCount::new(LEN)).bench_values(
bencher.with_inputs(|| vec![0u8; len]).counter(BytesCount::new(len)).bench_values(
|mut block| {
let mut protocol = Protocol::new("stream");
protocol.mix("key", &key);
Expand All @@ -45,12 +45,12 @@ fn stream<const LEN: usize>(bencher: divan::Bencher) {
);
}

#[divan::bench(consts = LENS)]
fn aead<const LEN: usize>(bencher: divan::Bencher) {
#[divan::bench(args = LENS)]
fn aead(bencher: divan::Bencher, len: usize) {
let key = [0u8; 32];
let nonce = [0u8; 16];
let ad = [0u8; 32];
bencher.with_inputs(|| vec![0u8; LEN + TAG_LEN]).counter(BytesCount::new(LEN)).bench_values(
bencher.with_inputs(|| vec![0u8; len + TAG_LEN]).counter(BytesCount::new(len)).bench_values(
|mut block| {
let mut protocol = Protocol::new("aead");
protocol.mix("key", &key);
Expand All @@ -62,10 +62,10 @@ fn aead<const LEN: usize>(bencher: divan::Bencher) {
);
}

#[divan::bench(consts = LENS)]
fn prf<const LEN: usize>(bencher: divan::Bencher) {
#[divan::bench(args = LENS)]
fn prf(bencher: divan::Bencher, len: usize) {
let key = [0u8; 32];
bencher.with_inputs(|| vec![0u8; LEN]).counter(BytesCount::new(LEN)).bench_values(
bencher.with_inputs(|| vec![0u8; len]).counter(BytesCount::new(len)).bench_values(
|mut block| {
let mut protocol = Protocol::new("prf");
protocol.mix("key", &key);
Expand Down

0 comments on commit ae8dd6e

Please sign in to comment.