bheisler / iai

Experimental one-shot benchmarking/profiling harness for Rust
Apache License 2.0
578 stars 23 forks source link

Example showing how to use iai_macro #5

Open HEnquist opened 3 years ago

HEnquist commented 3 years ago

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?

bheisler commented 3 years ago

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].

HEnquist commented 3 years ago

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 commented 3 years ago

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