You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Benchmarks don't currently support before_each and after_each. That's somewhat surprising to users of the crate. My issue with just adding it like for tests is that bench takes an argument (the benchmarker that you call iter on). So with the current setup you could then refer to this argument in the before and after blocks as they're essentially just copied into the bench scope!
That to me is even weirder and could potentially produce even more surprises than just not having before and after at all. What I'm thinking of doing instead is the following:
describe! a_benchmark {
setup {// some setup code}
bench "my benchmark"{// The code you want to run in the actual benchmark}
teardown {// Some cleanup code}}
This would then transform into the following code:
#[bench]fnmy_benchmark(b:&mutBencher){// some setup code
b.iter(|| {// The code you want to run in the actual benchmark})// Some cleanup code}
This would then mean that we could get rid of the argument to bench and do all the plumbing for you. I'm not convinced if this is really the right way to do it though as it would require you to have the setup there always even if you just write one benchmark.
I'll mull it over some more and maybe try implementing it.
The text was updated successfully, but these errors were encountered:
Benchmarks don't currently support
before_each
andafter_each
. That's somewhat surprising to users of the crate. My issue with just adding it like for tests is thatbench
takes an argument (the benchmarker that you calliter
on). So with the current setup you could then refer to this argument in the before and after blocks as they're essentially just copied into thebench
scope!That to me is even weirder and could potentially produce even more surprises than just not having before and after at all. What I'm thinking of doing instead is the following:
This would then transform into the following code:
This would then mean that we could get rid of the argument to
bench
and do all the plumbing for you. I'm not convinced if this is really the right way to do it though as it would require you to have thesetup
there always even if you just write one benchmark.I'll mull it over some more and maybe try implementing it.
The text was updated successfully, but these errors were encountered: