Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup and teardown support for benchmarks #70

Open
ujh opened this issue Oct 20, 2016 · 0 comments
Open

Setup and teardown support for benchmarks #70

ujh opened this issue Oct 20, 2016 · 0 comments

Comments

@ujh
Copy link
Collaborator

ujh commented Oct 20, 2016

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]
fn my_benchmark(b: &mut Bencher) {
  // 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant