Repository: google/benchmark
File: src/json_reporter.cc (C++)

Code before:
      out << indent << FormatKV("cpu_time", run.GetAdjustedCPUTime());
    } else {
      assert(run.aggregate_unit == StatisticUnit::kPercentage);
      out << indent << FormatKV("real_time", run.real_accumulated_time)
          << ",\n";
      out << indent << FormatKV("cpu_time", run.cpu_accumulated_time);
    }
    out << ",\n"
        << indent << FormatKV("time_unit", GetTimeUnitString(run.time_unit));
  } else if (run.report_big_o) {
    out << indent << FormatKV("cpu_coefficient", run.GetAdjustedCPUTime())
        << ",\n";
    out << indent << FormatKV("real_coefficient", run.GetAdjustedRealTime())
        << ",\n";
    out << indent << FormatKV("big_o", GetBigOString(run.complexity)) << ",\n";
    out << indent << FormatKV("time_unit", GetTimeUnitString(run.time_unit));
  } else if (run.report_rms) {
    out << indent << FormatKV("rms", run.GetAdjustedCPUTime());
  }

  for (const auto& c : run.counters) {
    out << ",\n" << indent << FormatKV(c.first, c.second);
  }

  if (run.memory_result.memory_iterations > 0) {
    const MemoryManager::Result& memory_result{run.memory_result};
    out << ",\n" << indent << FormatKV("allocs_per_iter", run.allocs_per_iter);
    out << ",\n"
        << indent << FormatKV("max_bytes_used", memory_result.max_bytes_used);

    auto report_if_present = [&out, &indent](const std::string& label,
                                             int64_t val) {
      if (val != MemoryManager::TombstoneValue) {
        out << ",\n" << indent << FormatKV(label, val);
      }
    };

    report_if_present("total_allocated_bytes",
                      memory_result.total_allocated_bytes);
    report_if_present("net_heap_growth", memory_result.net_heap_growth);
  }

  if (!run.report_label.empty()) {
    out << ",\n" << indent << FormatKV("label", run.report_label);
  }
  out << '\n';
}

const int64_t MemoryManager::TombstoneValue =
    std::numeric_limits<int64_t>::max();


Review comment (suggestion):
`    const auto& memory_result = run.memory_result;`

Code after:
      out << indent << FormatKV("cpu_time", run.GetAdjustedCPUTime());
    } else {
      assert(run.aggregate_unit == StatisticUnit::kPercentage);
      out << indent << FormatKV("real_time", run.real_accumulated_time)
          << ",\n";
      out << indent << FormatKV("cpu_time", run.cpu_accumulated_time);
    }
    out << ",\n"
        << indent << FormatKV("time_unit", GetTimeUnitString(run.time_unit));
  } else if (run.report_big_o) {
    out << indent << FormatKV("cpu_coefficient", run.GetAdjustedCPUTime())
        << ",\n";
    out << indent << FormatKV("real_coefficient", run.GetAdjustedRealTime())
        << ",\n";
    out << indent << FormatKV("big_o", GetBigOString(run.complexity)) << ",\n";
    out << indent << FormatKV("time_unit", GetTimeUnitString(run.time_unit));
  } else if (run.report_rms) {
    out << indent << FormatKV("rms", run.GetAdjustedCPUTime());
  }

  for (const auto& c : run.counters) {
    out << ",\n" << indent << FormatKV(c.first, c.second);
  }

  if (run.memory_result.memory_iterations > 0) {
    const auto& memory_result = run.memory_result;
    out << ",\n" << indent << FormatKV("allocs_per_iter", run.allocs_per_iter);
    out << ",\n"
        << indent << FormatKV("max_bytes_used", memory_result.max_bytes_used);

    auto report_if_present = [&out, &indent](const std::string& label,
                                             int64_t val) {
      if (val != MemoryManager::TombstoneValue) {
        out << ",\n" << indent << FormatKV(label, val);
      }
    };

    report_if_present("total_allocated_bytes",
                      memory_result.total_allocated_bytes);
    report_if_present("net_heap_growth", memory_result.net_heap_growth);
  }

  if (!run.report_label.empty()) {
    out << ",\n" << indent << FormatKV("label", run.report_label);
  }
  out << '\n';
}

}  // end namespace benchmark