Commit 2e76cb01 authored by Rajat Goel's avatar Rajat Goel Committed by Tudor Bosman

Adding support to output benchmarks result in JSON

Summary: The main reason being so that they can be fed to some automated systems, if required.

Test Plan: Just ran few benchmarks locally

Reviewed By: andrewjcg@fb.com

FB internal diff: D501025
parent 9eaebc0d
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "Benchmark.h" #include "Benchmark.h"
#include "Foreach.h" #include "Foreach.h"
#include "json.h"
#include "String.h" #include "String.h"
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
...@@ -29,6 +30,7 @@ ...@@ -29,6 +30,7 @@
using namespace std; using namespace std;
DEFINE_bool(benchmark, false, "Run benchmarks."); DEFINE_bool(benchmark, false, "Run benchmarks.");
DEFINE_bool(json, false, "Output in JSON format.");
namespace folly { namespace folly {
...@@ -296,7 +298,7 @@ static string humanReadable(double n, unsigned int decimals) { ...@@ -296,7 +298,7 @@ static string humanReadable(double n, unsigned int decimals) {
return stringPrintf("%*.*f%c", decimals + 3 + 1, decimals, n, suffix); return stringPrintf("%*.*f%c", decimals + 3 + 1, decimals, n, suffix);
} }
static void printBenchmarkResults( static void printBenchmarkResultsAsTable(
const vector<tuple<const char*, const char*, double> >& data) { const vector<tuple<const char*, const char*, double> >& data) {
// Width available // Width available
static const uint columns = 76; static const uint columns = 76;
...@@ -366,6 +368,26 @@ static void printBenchmarkResults( ...@@ -366,6 +368,26 @@ static void printBenchmarkResults(
separator('='); separator('=');
} }
static void printBenchmarkResultsAsJson(
const vector<tuple<const char*, const char*, double> >& data) {
dynamic d = dynamic::object;
for (auto& datum: data) {
d[std::get<1>(datum)] = std::get<2>(datum) * 1000.;
}
printf("%s\n", toPrettyJson(d).c_str());
}
static void printBenchmarkResults(
const vector<tuple<const char*, const char*, double> >& data) {
if (FLAGS_json) {
printBenchmarkResultsAsJson(data);
} else {
printBenchmarkResultsAsTable(data);
}
}
void runBenchmarks() { void runBenchmarks() {
CHECK(!benchmarks.empty()); CHECK(!benchmarks.empty());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment