Allow BenchmarkSuspender to be created in an initially-dismissed state
Summary:
Suppose we have this:
```
void myBenchmark() {
do_setup();
do_processing();
}
```
Maybe we want to benchmark both including and excluding the setup. Today, we have some options:
One possibility:
```
void myBenchmarkIncludeSetup() {
do_setup();
do_processing();
}
void myBenchmarkExcludeSetup() {
BENCHMARK_SUSPEND {
do_setup();
}
do_processing();
}
```
Another possibility -- but this is pretty verbose:
```
void myBenchmark(bool exclude_setup) {
BenchmarkSuspender bs;
bs.dismiss()
if(exclude_setup) bs.rehire();
do_setup();
if(exclude_setup) bs.dismiss();
do_processing();
}
```
We can simplify if we no longer require that BenchmarkSuspenders begin life as "hired".
After this diff, we can instead do this. I think it reads better:
```
void myBenchmark(bool exclude_setup) {
BenchmarkSuspender bs{BenchmarkSuspender::Dismissed};
if(exclude_setup) bs.rehire();
do_setup();
if(exclude_setup) bs.dismiss();
do_processing();
}
```
Reviewed By: yfeldblum, ot, luciang
Differential Revision: D28151318
fbshipit-source-id: bca5a41158430844748a812bbe30173adbad5307
Showing
Please register or sign in to comment