[Workflow] Try to fix code-formatter failing to find changes in some cases.
[llvm-project.git] / third-party / benchmark / test / fixture_test.cc
blobaf650dbd0661a7a6cb553458b55cf75992b2cf70
2 #include <cassert>
3 #include <memory>
5 #include "benchmark/benchmark.h"
7 #define FIXTURE_BECHMARK_NAME MyFixture
9 class FIXTURE_BECHMARK_NAME : public ::benchmark::Fixture {
10 public:
11 void SetUp(const ::benchmark::State& state) BENCHMARK_OVERRIDE {
12 if (state.thread_index() == 0) {
13 assert(data.get() == nullptr);
14 data.reset(new int(42));
18 void TearDown(const ::benchmark::State& state) BENCHMARK_OVERRIDE {
19 if (state.thread_index() == 0) {
20 assert(data.get() != nullptr);
21 data.reset();
25 ~FIXTURE_BECHMARK_NAME() { assert(data == nullptr); }
27 std::unique_ptr<int> data;
30 BENCHMARK_F(FIXTURE_BECHMARK_NAME, Foo)(benchmark::State& st) {
31 assert(data.get() != nullptr);
32 assert(*data == 42);
33 for (auto _ : st) {
37 BENCHMARK_DEFINE_F(FIXTURE_BECHMARK_NAME, Bar)(benchmark::State& st) {
38 if (st.thread_index() == 0) {
39 assert(data.get() != nullptr);
40 assert(*data == 42);
42 for (auto _ : st) {
43 assert(data.get() != nullptr);
44 assert(*data == 42);
46 st.SetItemsProcessed(st.range(0));
48 BENCHMARK_REGISTER_F(FIXTURE_BECHMARK_NAME, Bar)->Arg(42);
49 BENCHMARK_REGISTER_F(FIXTURE_BECHMARK_NAME, Bar)->Arg(42)->ThreadPerCpu();
51 BENCHMARK_MAIN();