Commit 7a875f2a authored by Mark Santaniello's avatar Mark Santaniello Committed by Facebook GitHub Bot

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
parent 6cd060f1
......@@ -115,7 +115,12 @@ struct BenchmarkSuspender {
using TimePoint = Clock::time_point;
using Duration = Clock::duration;
BenchmarkSuspender() { start = Clock::now(); }
struct DismissedTag {};
static inline constexpr DismissedTag Dismissed{};
BenchmarkSuspender() : start(Clock::now()) {}
explicit BenchmarkSuspender(DismissedTag) : start(TimePoint{}) {}
BenchmarkSuspender(const BenchmarkSuspender&) = delete;
BenchmarkSuspender(BenchmarkSuspender&& rhs) noexcept {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment