1 
2 #include "benchmark/benchmark.h"
3 
4 #include <cassert>
5 #include <memory>
6 
7 class MyFixture : public ::benchmark::Fixture {
8  public:
SetUp(const::benchmark::State &)9   void SetUp(const ::benchmark::State&) {
10     assert(data.get() == nullptr);
11     data.reset(new int(42));
12   }
13 
TearDown()14   void TearDown() {
15     assert(data.get() != nullptr);
16     data.release();
17   }
18 
~MyFixture()19   ~MyFixture() {
20     assert(data == nullptr);
21   }
22 
23   std::unique_ptr<int> data;
24 };
25 
26 
BENCHMARK_F(MyFixture,Foo)27 BENCHMARK_F(MyFixture, Foo)(benchmark::State& st) {
28   assert(data.get() != nullptr);
29   assert(*data == 42);
30   while (st.KeepRunning()) {
31   }
32 }
33 
BENCHMARK_DEFINE_F(MyFixture,Bar)34 BENCHMARK_DEFINE_F(MyFixture, Bar)(benchmark::State& st) {
35   while (st.KeepRunning()) {
36   }
37   st.SetItemsProcessed(st.range_x());
38 }
39 BENCHMARK_REGISTER_F(MyFixture, Bar)->Arg(42);
40 
41 BENCHMARK_MAIN()
42