Skip to content

Commit

Permalink
Update from iai to iai-callgrind
Browse files Browse the repository at this point in the history
This requires the iai-callgrind-runner binary to be installed (possible
via cargo install), but has the advantage of working with a recent
valgrind version (iai seems to be unmaintained for the past years).
  • Loading branch information
shahn committed Oct 28, 2024
1 parent b8d294e commit 48a3e18
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 7 deletions.
89 changes: 85 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ serde_json = { version = "1", default-features = false, features = ["alloc"] }

[dev-dependencies]
criterion = "0.5.1"
iai = "0.1.1"
iai-callgrind = "0.14.0"
once_cell = "1.20.2"
pretty_assertions.workspace = true
rasn-pkix = { path = "standards/pkix" }
Expand Down
11 changes: 9 additions & 2 deletions benches/iai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@ mod common;

use common::*;

use iai_callgrind::{library_benchmark, library_benchmark_group, main};
use std::hint::black_box;

macro_rules! encoding_rules {
($($encoding: ident ($encoding_fn:ident, $decoding_fn:ident)),+ $(,)?) => {
$(
#[library_benchmark]
fn $encoding_fn() {
let data = iai::black_box(bench_default());
let data = black_box(bench_default());

rasn::$encoding::encode(&data).unwrap();
}

#[library_benchmark]
fn $decoding_fn() {
use once_cell::sync::Lazy;

Expand All @@ -23,7 +28,9 @@ macro_rules! encoding_rules {

)+

iai::main!{$($encoding_fn, $decoding_fn),+}
library_benchmark_group!(name = encode; benchmarks = $($encoding_fn),+);
library_benchmark_group!(name = decode; benchmarks = $($decoding_fn),+);
main!(library_benchmark_groups = encode, decode);
}
}

Expand Down

0 comments on commit 48a3e18

Please sign in to comment.