Skip to content

Instantly share code, notes, and snippets.

@EricWF
Created January 6, 2018 21:05
Show Gist options
  • Select an option

  • Save EricWF/e033d66c024fe65f9e15705b653bd3f7 to your computer and use it in GitHub Desktop.

Select an option

Save EricWF/e033d66c024fe65f9e15705b653bd3f7 to your computer and use it in GitHub Desktop.
static bool have_entered_main = false;
static int num_constructed = 0;
class StaticInitFixtureTest : public ::benchmark::Fixture {
public:
StaticInitFixtureTest() {
++num_constructed;
assert(have_entered_main);
}
};
BENCHMARK_DEFINE_F(StaticInitFixtureTest, ConstructionHappensAtRuntime)(benchmark::State &st) {
for (auto _ : st) {
}
}
BENCHMARK_REGISTER_F(StaticInitFixtureTest, ConstructionHappensAtRuntime)->Arg(42);
BENCHMARK_F(StaticInitFixtureTest, ConstructionHappensAtRuntime2)(benchmark::State& st) {
for (auto _ : st) {
}
}
int main(int argc, char **argv) {
benchmark::Initialize(&argc, argv);
assert(num_constructed == 0);
have_entered_main = true;
::benchmark::RunSpecifiedBenchmarks();
assert(num_constructed == 2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment