memory_manager_test.cc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <memory>
  2. #include "../src/check.h"
  3. #include "benchmark/benchmark.h"
  4. #include "output_test.h"
  5. class TestMemoryManager : public benchmark::MemoryManager {
  6. void Start() {}
  7. void Stop(Result* result) {
  8. result->num_allocs = 42;
  9. result->max_bytes_used = 42000;
  10. }
  11. };
  12. void BM_empty(benchmark::State& state) {
  13. for (auto _ : state) {
  14. benchmark::DoNotOptimize(state.iterations());
  15. }
  16. }
  17. BENCHMARK(BM_empty);
  18. ADD_CASES(TC_ConsoleOut, {{"^BM_empty %console_report$"}});
  19. ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_empty\",$"},
  20. {"\"run_name\": \"BM_empty\",$", MR_Next},
  21. {"\"run_type\": \"iteration\",$", MR_Next},
  22. {"\"iterations\": %int,$", MR_Next},
  23. {"\"real_time\": %float,$", MR_Next},
  24. {"\"cpu_time\": %float,$", MR_Next},
  25. {"\"time_unit\": \"ns\",$", MR_Next},
  26. {"\"allocs_per_iter\": %float,$", MR_Next},
  27. {"\"max_bytes_used\": 42000$", MR_Next},
  28. {"}", MR_Next}});
  29. ADD_CASES(TC_CSVOut, {{"^\"BM_empty\",%csv_report$"}});
  30. int main(int argc, char *argv[]) {
  31. std::unique_ptr<benchmark::MemoryManager> mm(new TestMemoryManager());
  32. benchmark::RegisterMemoryManager(mm.get());
  33. RunOutputTests(argc, argv);
  34. benchmark::RegisterMemoryManager(nullptr);
  35. }