iai icon indicating copy to clipboard operation
iai copied to clipboard

initialization code

Open mimoo opened this issue 4 years ago • 4 comments

Hello,

I'm looking to run some initialization once before starting any benchmarks. How do I do this? Thanks!

I found my answer for criterion here: https://www.reddit.com/r/rust/comments/8uj5oa/criterion_benchmark_with_onetime_setup_also_how/ (btw it would be nice to have that answer in the FAQ), but I'm wondering about how to do that in iai.

mimoo avatar Dec 09 '21 22:12 mimoo

ok my undersrtanding is that the function is actually called a single time, so you can have the init function be part of it? Still, it'd be nice not to have that be part of the bench

fn bench_proof_creation() {
   // init code here
   // bench code here
}

iai::main!(bench_proof_creation);

mimoo avatar Dec 09 '21 22:12 mimoo

the README actually states this:

Con: Iai cannot exclude setup code from the measurements, where Criterion-rs can.

so perhaps a good way to exclude setup code is to bench the setup_code in addition of benching setup_code + stuff and then subtract.

mimoo avatar Jan 20 '22 21:01 mimoo

I set up an image buffer by storing it in a static, then obtaining a reference to it at runtime is effectively free. What setup are you doing at runtime?

LoganDark avatar Jun 19 '22 21:06 LoganDark

I'm initializing a large structs with a bug of vectors in it :o I guess I could serialize it, but then changing the code would break the serialization

mimoo avatar Jun 20 '22 20:06 mimoo