~smspillaz/folly/folly-git-master

Viewing all changes in revision 9640.

  • Committer: Facebook GitHub Bot
  • Author(s): Mark Santaniello
  • Date: 2021-05-04 14:09:14 UTC
  • Revision ID: git-v1:7a875f2a359b85e07b8e4c84a77c9d1ccd6d1f34
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

expand all expand all

Show diffs side-by-side

added added

removed removed

Lines of Context: