[Reland][Runtimes] Merge 'compile_commands.json' files from runtimes build (#116303)
[llvm-project.git] / third-party / benchmark / test / fixture_test.cc
blobd1093ebf52fc83af7173e526aace7e9cb9227712
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) 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) override {
19 if (state.thread_index() == 0) {
20 assert(data.get() != nullptr);
21 data.reset();
25 ~FIXTURE_BECHMARK_NAME() override { 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();