-
Notifications
You must be signed in to change notification settings - Fork 22
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
Divan benchmarking PoC #140
Conversation
Hi, I noticed this PR and wanted to suggest a few improvements if I may 😄
#[divan::bench]
fn parse_postal(bencher: divan::Bencher) {
let input = divan::black_box(
include_str!("../tests/fixtures/postal_address.terminated.input.bnf")
);
bencher.bench(|| {
input.parse::<bnf::Grammar>().unwrap();
});
} This ensures each iteration gets an opaque input without the cost of storing duplicate inputs ( Similarly, #[divan::bench]
fn parse_infinite_nullable_grammar(bencher: divan::Bencher) {
let infinite_grammar: bnf::Grammar = "
<a> ::= '' | <b>
<b> ::= <a>"
.parse()
.unwrap();
let parse_count: usize = {
use rand::Rng;
let mut rng: rand::rngs::StdRng = rand::SeedableRng::seed_from_u64(0);
rng.gen_range(1..100);
};
bencher
.counter(parse_count)
.bench(|| {
let _: Vec<_> = infinite_grammar.parse_input("").take(parse_count).collect();
});
} However, you probably meant to have each iteration use a random #[divan::bench]
fn parse_infinite_nullable_grammar(bencher: divan::Bencher) {
use rand::Rng;
let infinite_grammar: bnf::Grammar = "
<a> ::= '' | <b>
<b> ::= <a>"
.parse()
.unwrap();
let mut rng: rand::rngs::StdRng = rand::SeedableRng::seed_from_u64(0);
bencher
.with_inputs(|| rng.gen_range(1..100))
.count_inputs_as::<divan::counter::ItemsCount>()
.bench_local_values(|parse_count| {
let _: Vec<_> = infinite_grammar.parse_input("").take(parse_count).collect();
});
} Note that |
@nvzqz wow thank you for the great notes! I applied your suggestions. thank you! |
Co-authored-by: Nikolai Vazquez <hello@nikolaivazquez.com>
Co-authored-by: Nikolai Vazquez <hello@nikolaivazquez.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I released 0.1.5
which adds black_box_drop
, which should make this code more legible 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very cool!
Closes #138
I ported the existing benchmarks to Divan as described in #138.
TODO