Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bench: Add digest overhead benchmarks. #1809

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ name = "agreement"
harness = false
path = "agreement.rs"

[[bench]]
name = "digest"
harness = false
path = "digest.rs"

[[bench]]
name = "ecdsa"
harness = false
Expand Down
49 changes: 49 additions & 0 deletions bench/digest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2023 Brian Smith.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#![allow(missing_docs)]

use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
use ring::digest;

static ALGORITHMS: &[(&str, &digest::Algorithm)] = &[
("sha256", &digest::SHA256),
("sha384", &digest::SHA384),
("sha512", &digest::SHA512),
];

const INPUT_LENGTHS: &[usize] = &[
// Benchmark that emphasizes overhead.
0,
];

fn oneshot(c: &mut Criterion) {
for &(alg_name, algorithm) in ALGORITHMS {
for input_len in INPUT_LENGTHS {
c.bench_with_input(
BenchmarkId::new(format!("digest::oneshot::{alg_name}"), 0),
input_len,
|b, &input_len| {
let input = vec![0u8; input_len];
b.iter(|| -> usize {
let digest = digest::digest(algorithm, &input);
black_box(digest.as_ref().len())
})
},
);
}
}
}

criterion_group!(digest, oneshot);
criterion_main!(digest);
Loading