Skip to content
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

Link benchmarked function to report output #818

Open
ChosunOne opened this issue Oct 4, 2024 · 0 comments
Open

Link benchmarked function to report output #818

ChosunOne opened this issue Oct 4, 2024 · 0 comments

Comments

@ChosunOne
Copy link

ChosunOne commented Oct 4, 2024

Is there a way to include a link to the function that is benched by a criterion benchmark run? I want to build some tools that will display performance of functions in my editor, but I don't want to have to rely on naming my benchmark with the path:line or fully qualified function name.

Given the function I want to bench:

fn foo(in: &str) -> usize {
    in.len()
}

and the corresponding benchmark:

fn foo_benchmark(c: &mut Criterion) {
    let example_in = "Some example data";
    c.bench_function("my descriptive benchmark name", |b| b.iter(|| foo(black_box(example_in))));
}

In the .json report I would like a way to link the benchmark result with the benched function:

{
"function": "fully::qualified::path::to::foo",
}

or

{
"function": "path/to/mod/with/foo:line_no",
}

If it can't be done now, it would be nice if in the benchmark I could explicitly register the function I want to associate with the bench, perhaps like:

fn foo_benchmark(c: &mut Criterion) {
    let example_in = "Some example data";
    c.bench_function("my descriptive benchmark name", |b| b.iter(|| foo(black_box(example_in))));
    c.register(foo) // Or maybe in the line above somehow
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant