/*
- * Copyright 2012 Facebook, Inc.
+ * Copyright 2016 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* limitations under the License.
*/
-#include "folly/Format.h"
+#include <folly/Format.h>
#include <glog/logging.h>
-#include "folly/FBVector.h"
-#include "folly/Benchmark.h"
-#include "folly/dynamic.h"
-#include "folly/json.h"
+#include <folly/FBVector.h>
+#include <folly/Benchmark.h>
+#include <folly/dynamic.h>
+#include <folly/json.h>
using namespace folly;
}
}
+BENCHMARK_DRAW_LINE()
+
+BENCHMARK(format_nested_strings, iters) {
+ while (iters--) {
+ fbstring out;
+ for (int i = 0; i < 1000; ++i) {
+ out.clear();
+ format(&out, "{} {}",
+ format("{} {}", i, i + 1).str(),
+ format("{} {}", -i, -i - 1).str());
+ }
+ }
+}
+
+BENCHMARK_RELATIVE(format_nested_fbstrings, iters) {
+ while (iters--) {
+ fbstring out;
+ for (int i = 0; i < 1000; ++i) {
+ out.clear();
+ format(&out, "{} {}",
+ format("{} {}", i, i + 1).fbstr(),
+ format("{} {}", -i, -i - 1).fbstr());
+ }
+ }
+}
+
+BENCHMARK_RELATIVE(format_nested_direct, iters) {
+ while (iters--) {
+ fbstring out;
+ for (int i = 0; i < 1000; ++i) {
+ out.clear();
+ format(&out, "{} {}",
+ format("{} {}", i, i + 1),
+ format("{} {}", -i, -i - 1));
+ }
+ }
+}
+
// Benchmark results on my dev server (dual-CPU Xeon L5520 @ 2.7GHz)
//
// ============================================================================
// ============================================================================
int main(int argc, char *argv[]) {
- google::ParseCommandLineFlags(&argc, &argv, true);
+ gflags::ParseCommandLineFlags(&argc, &argv, true);
runBenchmarks();
return 0;
}