2 #include "benchmark/benchmark.h"
7 class MyFixture
: public ::benchmark::Fixture
{
9 void SetUp(const ::benchmark::State
& state
) {
10 if (state
.thread_index
== 0) {
11 assert(data
.get() == nullptr);
12 data
.reset(new int(42));
16 void TearDown(const ::benchmark::State
& state
) {
17 if (state
.thread_index
== 0) {
18 assert(data
.get() != nullptr);
23 ~MyFixture() { assert(data
== nullptr); }
25 std::unique_ptr
<int> data
;
28 BENCHMARK_F(MyFixture
, Foo
)(benchmark::State
&st
) {
29 assert(data
.get() != nullptr);
35 BENCHMARK_DEFINE_F(MyFixture
, Bar
)(benchmark::State
& st
) {
36 if (st
.thread_index
== 0) {
37 assert(data
.get() != nullptr);
41 assert(data
.get() != nullptr);
44 st
.SetItemsProcessed(st
.range(0));
46 BENCHMARK_REGISTER_F(MyFixture
, Bar
)->Arg(42);
47 BENCHMARK_REGISTER_F(MyFixture
, Bar
)->Arg(42)->ThreadPerCpu();