Update Google Benchmark library
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@322812 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "benchmark/reporter.h"
|
||||
#include "benchmark/benchmark.h"
|
||||
#include "complexity.h"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -21,6 +21,8 @@
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
#include <iomanip> // for setprecision
|
||||
#include <limits>
|
||||
|
||||
#include "string_util.h"
|
||||
#include "timers.h"
|
||||
@@ -48,7 +50,14 @@ std::string FormatKV(std::string const& key, int64_t value) {
|
||||
}
|
||||
|
||||
std::string FormatKV(std::string const& key, double value) {
|
||||
return StringPrintF("\"%s\": %.2f", key.c_str(), value);
|
||||
std::stringstream ss;
|
||||
ss << '"' << key << "\": ";
|
||||
|
||||
const auto max_digits10 = std::numeric_limits<decltype (value)>::max_digits10;
|
||||
const auto max_fractional_digits10 = max_digits10 - 1;
|
||||
|
||||
ss << std::scientific << std::setprecision(max_fractional_digits10) << value;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
int64_t RoundDouble(double v) { return static_cast<int64_t>(v + 0.5); }
|
||||
@@ -68,13 +77,37 @@ bool JSONReporter::ReportContext(const Context& context) {
|
||||
std::string walltime_value = LocalDateTimeString();
|
||||
out << indent << FormatKV("date", walltime_value) << ",\n";
|
||||
|
||||
out << indent << FormatKV("num_cpus", static_cast<int64_t>(context.num_cpus))
|
||||
CPUInfo const& info = context.cpu_info;
|
||||
out << indent << FormatKV("num_cpus", static_cast<int64_t>(info.num_cpus))
|
||||
<< ",\n";
|
||||
out << indent << FormatKV("mhz_per_cpu", RoundDouble(context.mhz_per_cpu))
|
||||
out << indent
|
||||
<< FormatKV("mhz_per_cpu",
|
||||
RoundDouble(info.cycles_per_second / 1000000.0))
|
||||
<< ",\n";
|
||||
out << indent << FormatKV("cpu_scaling_enabled", context.cpu_scaling_enabled)
|
||||
out << indent << FormatKV("cpu_scaling_enabled", info.scaling_enabled)
|
||||
<< ",\n";
|
||||
|
||||
out << indent << "\"caches\": [\n";
|
||||
indent = std::string(6, ' ');
|
||||
std::string cache_indent(8, ' ');
|
||||
for (size_t i = 0; i < info.caches.size(); ++i) {
|
||||
auto& CI = info.caches[i];
|
||||
out << indent << "{\n";
|
||||
out << cache_indent << FormatKV("type", CI.type) << ",\n";
|
||||
out << cache_indent << FormatKV("level", static_cast<int64_t>(CI.level))
|
||||
<< ",\n";
|
||||
out << cache_indent
|
||||
<< FormatKV("size", static_cast<int64_t>(CI.size) * 1000u) << ",\n";
|
||||
out << cache_indent
|
||||
<< FormatKV("num_sharing", static_cast<int64_t>(CI.num_sharing))
|
||||
<< "\n";
|
||||
out << indent << "}";
|
||||
if (i != info.caches.size() - 1) out << ",";
|
||||
out << "\n";
|
||||
}
|
||||
indent = std::string(4, ' ');
|
||||
out << indent << "],\n";
|
||||
|
||||
#if defined(NDEBUG)
|
||||
const char build_type[] = "release";
|
||||
#else
|
||||
@@ -125,18 +158,18 @@ void JSONReporter::PrintRunData(Run const& run) {
|
||||
if (!run.report_big_o && !run.report_rms) {
|
||||
out << indent << FormatKV("iterations", run.iterations) << ",\n";
|
||||
out << indent
|
||||
<< FormatKV("real_time", RoundDouble(run.GetAdjustedRealTime()))
|
||||
<< FormatKV("real_time", run.GetAdjustedRealTime())
|
||||
<< ",\n";
|
||||
out << indent
|
||||
<< FormatKV("cpu_time", RoundDouble(run.GetAdjustedCPUTime()));
|
||||
<< FormatKV("cpu_time", run.GetAdjustedCPUTime());
|
||||
out << ",\n"
|
||||
<< indent << FormatKV("time_unit", GetTimeUnitString(run.time_unit));
|
||||
} else if (run.report_big_o) {
|
||||
out << indent
|
||||
<< FormatKV("cpu_coefficient", RoundDouble(run.GetAdjustedCPUTime()))
|
||||
<< FormatKV("cpu_coefficient", run.GetAdjustedCPUTime())
|
||||
<< ",\n";
|
||||
out << indent
|
||||
<< FormatKV("real_coefficient", RoundDouble(run.GetAdjustedRealTime()))
|
||||
<< FormatKV("real_coefficient", run.GetAdjustedRealTime())
|
||||
<< ",\n";
|
||||
out << indent << FormatKV("big_o", GetBigOString(run.complexity)) << ",\n";
|
||||
out << indent << FormatKV("time_unit", GetTimeUnitString(run.time_unit));
|
||||
@@ -147,17 +180,17 @@ void JSONReporter::PrintRunData(Run const& run) {
|
||||
if (run.bytes_per_second > 0.0) {
|
||||
out << ",\n"
|
||||
<< indent
|
||||
<< FormatKV("bytes_per_second", RoundDouble(run.bytes_per_second));
|
||||
<< FormatKV("bytes_per_second", run.bytes_per_second);
|
||||
}
|
||||
if (run.items_per_second > 0.0) {
|
||||
out << ",\n"
|
||||
<< indent
|
||||
<< FormatKV("items_per_second", RoundDouble(run.items_per_second));
|
||||
<< FormatKV("items_per_second", run.items_per_second);
|
||||
}
|
||||
for(auto &c : run.counters) {
|
||||
out << ",\n"
|
||||
<< indent
|
||||
<< FormatKV(c.first, RoundDouble(c.second));
|
||||
<< FormatKV(c.first, c.second);
|
||||
}
|
||||
if (!run.report_label.empty()) {
|
||||
out << ",\n" << indent << FormatKV("label", run.report_label);
|
||||
|
||||
Reference in New Issue
Block a user