criterion.rs icon indicating copy to clipboard operation
criterion.rs copied to clipboard

Benchmarking a function returning borrowed data

Open Licenser opened this issue 6 years ago • 3 comments

Hi, I was wondering how to benchmark a function that returns borrowed data within including the drop in he measures?

Licenser avatar Apr 09 '19 06:04 Licenser

Hey, thanks for trying Criterion.rs.

You might be looking for iter_batched_ref. If that's not it, could you explain your problem in more detail?

bheisler avatar Apr 10 '19 00:04 bheisler

Thanks for the quick reply :) I tried _ref but I’m not getting it to work sadly. I think it is about the lifetime of the input not he output in _ref? But I could be wrong - lifetimes are still my arch nemesis in rust -.- what I’m trying to do is get rid of this semicolon so that the drop happens outside the benchmark loop.

Licenser avatar Apr 10 '19 06:04 Licenser

Ah, I see what you mean now.

Unfortunately, I don't think that's currently possible. Worse, I'm not even certain that it's possible for Criterion.rs to support that. It ought to be safe - the returned reference should never outlive the input - but I have no idea how to convince rustc of that.

Sorry I can't be more helpful. I'll leave this open in case somebody out there knows some lifetime trickery I don't know. I've put up a minimal test case on the Playground in case anyone wants to take a go.

bheisler avatar Apr 12 '19 01:04 bheisler