-
-
Save BD103/cb7becebf2509accbd31973c73d7ad0d to your computer and use it in GitHub Desktop.
Benchmarking `#[track_caller]`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn untracked(x: bool) { | |
if x { | |
panic!("Untracked"); | |
} | |
} | |
#[track_caller] | |
pub fn tracked(x: bool) { | |
if x { | |
panic!("Tracked"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cargo bench | |
... | |
tracked false time: [1.5369 ns 1.5376 ns 1.5383 ns] | |
Found 8 outliers among 100 measurements (8.00%) | |
5 (5.00%) high mild | |
3 (3.00%) high severe | |
untracked false time: [1.5371 ns 1.5376 ns 1.5382 ns] | |
Found 5 outliers among 100 measurements (5.00%) | |
3 (3.00%) high mild | |
2 (2.00%) high severe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | |
use playground::*; | |
fn bench(c: &mut Criterion) { | |
c | |
.bench_function("tracked false", |b| b.iter(|| tracked(black_box(false)))) | |
.bench_function("untracked false", |b| b.iter(|| untracked(black_box(false)))); | |
// c.bench_function("tracked true", |b| b.iter(|| tracked(black_box(true)))) | |
// .bench_function("untracked true", |b| b.iter(|| untracked(black_box(true)))); | |
} | |
criterion_group!(benches, bench); | |
criterion_main!(benches); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment