Skip to content
Browse files

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
  • Loading branch information...
1 parent 9eaebc0 commit 2e76cb012388630c6e167e9ea50395d0ef597e76 Rajat Goel committed with tudor Jun 25, 2012
Showing with 23 additions and 1 deletion.
  1. +23 −1 folly/Benchmark.cpp
View
24 folly/Benchmark.cpp
@@ -18,6 +18,7 @@
#include "Benchmark.h"
#include "Foreach.h"
+#include "json.h"
#include "String.h"
#include <algorithm>
#include <cmath>
@@ -29,6 +30,7 @@
using namespace std;
DEFINE_bool(benchmark, false, "Run benchmarks.");
+DEFINE_bool(json, false, "Output in JSON format.");
namespace folly {
@@ -296,7 +298,7 @@ static string humanReadable(double n, unsigned int decimals) {
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) {
// Width available
static const uint columns = 76;
@@ -366,6 +368,26 @@ static void printBenchmarkResults(
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() {
CHECK(!benchmarks.empty());

0 comments on commit 2e76cb0

Please sign in to comment.
Something went wrong with that request. Please try again.