[Reland][Runtimes] Merge 'compile_commands.json' files from runtimes build (#116303)
[llvm-project.git] / third-party / benchmark / test / memory_manager_test.cc
blob4df674d586ed7344acf9a3892e8b6e0c26141e05
1 #include <memory>
3 #include "../src/check.h"
4 #include "benchmark/benchmark.h"
5 #include "output_test.h"
7 class TestMemoryManager : public benchmark::MemoryManager {
8 void Start() override {}
9 void Stop(Result& result) override {
10 result.num_allocs = 42;
11 result.max_bytes_used = 42000;
15 void BM_empty(benchmark::State& state) {
16 for (auto _ : state) {
17 auto iterations = double(state.iterations()) * double(state.iterations());
18 benchmark::DoNotOptimize(iterations);
21 BENCHMARK(BM_empty);
23 ADD_CASES(TC_ConsoleOut, {{"^BM_empty %console_report$"}});
24 ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_empty\",$"},
25 {"\"family_index\": 0,$", MR_Next},
26 {"\"per_family_instance_index\": 0,$", MR_Next},
27 {"\"run_name\": \"BM_empty\",$", MR_Next},
28 {"\"run_type\": \"iteration\",$", MR_Next},
29 {"\"repetitions\": 1,$", MR_Next},
30 {"\"repetition_index\": 0,$", MR_Next},
31 {"\"threads\": 1,$", MR_Next},
32 {"\"iterations\": %int,$", MR_Next},
33 {"\"real_time\": %float,$", MR_Next},
34 {"\"cpu_time\": %float,$", MR_Next},
35 {"\"time_unit\": \"ns\",$", MR_Next},
36 {"\"allocs_per_iter\": %float,$", MR_Next},
37 {"\"max_bytes_used\": 42000$", MR_Next},
38 {"}", MR_Next}});
39 ADD_CASES(TC_CSVOut, {{"^\"BM_empty\",%csv_report$"}});
41 int main(int argc, char* argv[]) {
42 std::unique_ptr<benchmark::MemoryManager> mm(new TestMemoryManager());
44 benchmark::RegisterMemoryManager(mm.get());
45 RunOutputTests(argc, argv);
46 benchmark::RegisterMemoryManager(nullptr);