flamegraph-rs / flamegraph

Easy flamegraphs for Rust projects and everything else, without Perl or pipes <3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cargo flamegraph bench not working (nightly)

johncardiologs opened this issue · comments

Hi,

I have a main.rs file which has a bench, as such:

#![feature(test)]
extern crate test;

#[cfg(test)]
mod tests {
    use test::{black_box, Bencher};

    #[bench]
    fn bench_stuff(b: &mut Bencher) {
        let s = "hello ";
        b.iter(|| {
            for i in 0..100 {
                black_box(do_stuff(s.to_string()));
            }
        });
    }

fn do_stuff(s: String) -> String {
    return s + " world!";
}

I'm using Rust nightly. I've installed flamegraph & perf. None of these commands are working for me:

str_bench git:(main) ✗ cargo flamegraph --bench bench_stuff
error: no bench target named `bench_stuff`
Error: cargo build failed

➜  str_bench git:(main) ✗ cargo flamegraph --bench bench_stuff -- --bench
error: no bench target named `bench_stuff`
Error: cargo build failed

cargo bench, however, works just fine.

Thanks for any help.

Oh, I hadn't realized the proper way to do this was with the Criterion crate. Using it worked for me.

It's not the criterion crate per se, but I think Cargo wouldn't be able to find your benchmark targets in the way you set it up before. Anyway, happy you solved it!