bheisler / iai

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

initialization code #23

Open mimoo opened 2 years ago

mimoo commented 2 years ago

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

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

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.

LoganDark commented 2 years ago

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?

mimoo commented 2 years ago

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