Benchmark Multiple Steps Separately Within A Single Bench Test


It looks like the current implementation of Bencher only stores a single benchmark result. Even if you call iter() more than once, your result is always overwritten during the latest call.

It would be great if we could call iter (or some other appropriately named method) one or more times, and then have the bencher report all of the results.

Here’s the kind of code I would love for this to support:

fn bench(b: &mut Bencher) {
    let source: String = /*...*/;
    let program = b.bench("precompile", || precompile(source));
    b.bench("interpret", || interpret(program));

Notice that I have replaced iter with a method called bench and added an argument to each which describes the kind of thing I am benchmarking. Think of that as the “label” used to distinguish between times recorded within a single benchmark test.

The reason this is convenient is because it lets me benchmark both my precompilation step and my interpret step in a single benchmark separately. I need the result of the precompilation step to do the interpretation step so doing them in separate benchmark functions is a waste and not as accurate of a picture.

The current state of things allows me to know the time of both together, or one at a time. It would be great if we could support a more granular API.