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