iai icon indicating copy to clipboard operation
iai copied to clipboard

Example showing how to use iai_macro

Open HEnquist opened this issue 4 years ago • 3 comments

I played a bit with iai yesterday and was really impressed by the stable results. Then I also made a quick attempt to use the iai_macro but couldn't figure out what to do. Could you add a simple example?

HEnquist avatar Jan 26 '21 08:01 HEnquist

Hey, thanks for trying Iai. Good suggestion.

In the meantime, it's basically the same deal as for Criterion.rs, only use #[iai] for your benchmark functions instead of #[criterion].

bheisler avatar Jan 26 '21 23:01 bheisler

Got it! I had disabled the testing harness. I enabled it again and things started working just fine.

Note that for #[criterion] benchmarks, we don't need to disable the normal testing harness as we do with regular Criterion.rs benchmarks.

I read this as "it doesn't matter if you disable the normal testing harness or not". But I guess the harness is really needed.

I think just copy-pasting this: https://github.com/bheisler/iai/blob/main/macro/benches/test_macro_bench.rs to the readme, together with the relevant bits of Cargo.toml and two lines of explanation would be enough.

HEnquist avatar Jan 27 '21 07:01 HEnquist

Please see https://github.com/bheisler/iai/pull/6

HEnquist avatar Jan 27 '21 07:01 HEnquist