Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
replace criterion with divan
  • Loading branch information
aumetra committed May 11, 2024
commit 56e0bea1d041873577101da189abeb6ed8c0319c
194 changes: 42 additions & 152 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 lib/http-signatures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ tick-tock-mock = { path = "../tick-tock-mock" }
tracing = { version = "0.1.40", default-features = false, optional = true }

[dev-dependencies]
criterion = "0.5.1"
divan = "0.1.14"
tokio = { version = "1.37.0", features = ["macros", "rt"] }

[features]
Expand Down
25 changes: 11 additions & 14 deletions lib/http-signatures/benches/build_cavage_signature_string.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use criterion::{criterion_group, criterion_main, Criterion};
use divan::Bencher;
use http::{Method, Request, Uri};
use std::hint::black_box;

const CAVAGE_HEADER: &str =
r#"keyId="Test",algorithm="rsa-sha256",headers="(request-target) host date",signature="qdx""#;

fn build_cavage_signature_string1(c: &mut Criterion) {
#[divan::bench]
fn build_cavage_signature_string(bencher: Bencher<'_, '_>) {
let signature_header = http_signatures::cavage::parse(CAVAGE_HEADER).unwrap();
let request = Request::builder()
.method(Method::GET)
Expand All @@ -21,18 +22,14 @@ fn build_cavage_signature_string1(c: &mut Criterion) {
.body(())
.unwrap();

c.bench_function("build_cavage_signature_string", |b| {
b.iter(|| {
let _ = black_box(http_signatures::cavage::signature_string::construct(
black_box(&request),
black_box(&signature_header),
));
});
bencher.bench(|| {
http_signatures::cavage::signature_string::construct(
black_box(&request),
black_box(&signature_header),
)
});
}

criterion_group!(
build_cavage_signature_string,
build_cavage_signature_string1
);
criterion_main!(build_cavage_signature_string);
fn main() {
divan::main();
}
26 changes: 10 additions & 16 deletions lib/http-signatures/benches/parse_cavage_header.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
use criterion::{criterion_group, criterion_main, Criterion};
use divan::{black_box, black_box_drop};
use http_signatures::cavage;
use std::hint::black_box;

const CAVAGE_HEADER_1: &str = r#"keyId="Test",algorithm="rsa-sha256",headers="(request-target) host date",signature="qdx+H7PHHDZgy4y/Ahn9Tny9V3GP6YgBPyUXMmoxWtLbHpUnXS2mg2+SbrQDMCJypxBLSPQR2aAjn7ndmw2iicw3HMbe8VfEdKFYRqzic+efkb3nndiv/x1xSHDJWeSWkx3ButlYSuBskLu6kd9Fswtemr3lgdDEmn04swr2Os0=""#;
const CAVAGE_HEADER_2: &str = r#"keyId="Test",algorithm="rsa-sha256",created=1402170695, expires=1402170699,headers="(request-target) (created) (expires) host date content-type digest content-length",signature="vSdrb+dS3EceC9bcwHSo4MlyKS59iFIrhgYkz8+oVLEEzmYZZvRs8rgOp+63LEM3v+MFHB32NfpB2bEKBIvB1q52LaEUHFv120V01IL+TAD48XaERZFukWgHoBTLMhYS2Gb51gWxpeIq8knRmPnYePbF5MOkR0Zkly4zKH7s1dE=""#;

fn header1(c: &mut Criterion) {
c.bench_function("parse_cavage_header1", |b| {
b.iter(|| {
let _ = black_box(cavage::parse(black_box(CAVAGE_HEADER_1)));
});
});
#[divan::bench]
fn parse_cavage_header1() {
black_box_drop(cavage::parse(black_box(CAVAGE_HEADER_1)));
}

fn header2(c: &mut Criterion) {
c.bench_function("parse_cavage_header2", |b| {
b.iter(|| {
let _ = black_box(cavage::parse(black_box(CAVAGE_HEADER_2)));
});
});
#[divan::bench]
fn parse_cavage_header2() {
black_box_drop(cavage::parse(black_box(CAVAGE_HEADER_2)));
}

criterion_group!(parse_cavage_header, header1, header2);
criterion_main!(parse_cavage_header);
fn main() {
divan::main();
}
Loading