Skip to content

Commit

Permalink
use bench groups and args
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed May 12, 2024
1 parent 5ad0bb2 commit 165d4ba
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 40 deletions.
13 changes: 4 additions & 9 deletions lib/http-signatures/benches/parse_cavage_header.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use divan::{black_box, black_box_drop};
use divan::black_box_drop;
use http_signatures::cavage;

#[global_allocator]
Expand All @@ -7,14 +7,9 @@ static GLOBAL: divan::AllocProfiler = divan::AllocProfiler::system();
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=""#;

#[divan::bench]
fn parse_cavage_header1() {
black_box_drop(cavage::parse(black_box(CAVAGE_HEADER_1)));
}

#[divan::bench]
fn parse_cavage_header2() {
black_box_drop(cavage::parse(black_box(CAVAGE_HEADER_2)));
#[divan::bench(args = [CAVAGE_HEADER_1, CAVAGE_HEADER_2])]
fn parse_cavage_header(header: &str) {
black_box_drop(cavage::parse(header));
}

fn main() {
Expand Down
14 changes: 7 additions & 7 deletions lib/masto-id-convert/benches/process.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#![allow(clippy::unreadable_literal)]

use divan::{black_box, black_box_drop};
use divan::black_box_drop;

#[global_allocator]
static GLOBAL: divan::AllocProfiler = divan::AllocProfiler::system();

#[divan::bench(name = "process integer 110368129515784116")]
fn process_u64() {
black_box_drop(masto_id_convert::process_u64(black_box(110368129515784116)));
#[divan::bench(name = "process integer", args = [110368129515784116])]
fn process_u64(id: u64) {
black_box_drop(masto_id_convert::process_u64(id));
}

#[divan::bench(name = "process ASCII 110368129515784116")]
fn process_ascii() {
black_box_drop(masto_id_convert::process(black_box("110368129515784116")));
#[divan::bench(name = "process ASCII", args = ["110368129515784116"])]
fn process_ascii(id: &str) {
black_box_drop(masto_id_convert::process(id));
}

fn main() {
Expand Down
6 changes: 3 additions & 3 deletions lib/post-process/benches/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ static GLOBAL: divan::AllocProfiler = divan::AllocProfiler::system();

const SIMPLE_POST: &str = "Hello, #World! This is a benchmark for the post transformer of @kitsune";

#[divan::bench]
fn simple_bench() -> post_process::Result<String> {
#[divan::bench(args = [SIMPLE_POST])]
fn simple_bench(post: &str) -> post_process::Result<String> {
block_on(post_process::transform(
black_box(SIMPLE_POST),
post,
black_box(|item| future::ready(Ok(item))),
))
}
Expand Down
51 changes: 30 additions & 21 deletions lib/tick-tock-mock/benches/simple_now.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
use divan::{black_box, Bencher};
use std::time::{Duration, SystemTime};
use tick_tock_mock::{Clock, DeltaDirection};

#[global_allocator]
static GLOBAL: divan::AllocProfiler = divan::AllocProfiler::system();

#[divan::bench]
fn std_systemtime_now() -> SystemTime {
black_box(SystemTime::now())
}
#[divan::bench_group]
mod std {
use divan::black_box;
use std::time::SystemTime;

#[divan::bench]
fn ttm_now_tl() -> SystemTime {
black_box(tick_tock_mock::now())
#[divan::bench]
fn systemtime_now() -> SystemTime {
black_box(SystemTime::now())
}
}

#[divan::bench]
fn ttm_now_simple(bencher: Bencher<'_, '_>) {
let clock = Clock::new();
bencher.bench(|| black_box(clock.now()));
}
#[divan::bench_group]
mod tick_tock_mock {
use divan::{black_box, Bencher};
use std::time::{Duration, SystemTime};
use tick_tock_mock::{Clock, DeltaDirection};

#[divan::bench]
fn now_thread_local() -> SystemTime {
black_box(tick_tock_mock::now())
}

#[divan::bench]
fn now(bencher: Bencher<'_, '_>) {
let clock = Clock::new();
bencher.bench(|| black_box(clock.now()));
}

#[divan::bench]
fn ttm_now_mock(bencher: Bencher<'_, '_>) {
let (clock, mock) = Clock::mockable();
mock.adjust(DeltaDirection::Add, Duration::from_secs(1));
#[divan::bench]
fn now_mocked(bencher: Bencher<'_, '_>) {
let (clock, mock) = Clock::mockable();
mock.adjust(DeltaDirection::Add, Duration::from_secs(1));

bencher.bench(|| black_box(clock.now()));
bencher.bench(|| black_box(clock.now()));
}
}

fn main() {
Expand Down

0 comments on commit 165d4ba

Please sign in to comment.