[llvm-readobj] - Implement LLVM-style dumping for .stack_sizes sections.
[llvm-complete.git] / utils / benchmark / test / fixture_test.cc
blob1462b10f02f96325354344f07d8c494ee7f8f345
2 #include "benchmark/benchmark.h"
4 #include <cassert>
5 #include <memory>
7 class MyFixture : public ::benchmark::Fixture {
8 public:
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);
19 data.reset();
23 ~MyFixture() { assert(data == nullptr); }
25 std::unique_ptr<int> data;
28 BENCHMARK_F(MyFixture, Foo)(benchmark::State &st) {
29 assert(data.get() != nullptr);
30 assert(*data == 42);
31 for (auto _ : st) {
35 BENCHMARK_DEFINE_F(MyFixture, Bar)(benchmark::State& st) {
36 if (st.thread_index == 0) {
37 assert(data.get() != nullptr);
38 assert(*data == 42);
40 for (auto _ : st) {
41 assert(data.get() != nullptr);
42 assert(*data == 42);
44 st.SetItemsProcessed(st.range(0));
46 BENCHMARK_REGISTER_F(MyFixture, Bar)->Arg(42);
47 BENCHMARK_REGISTER_F(MyFixture, Bar)->Arg(42)->ThreadPerCpu();
49 BENCHMARK_MAIN();