Ensure curly-braces around control-flow
[folly.git] / folly / futures / test / Benchmark.cpp
index 64d4a44f7e2422fce3e7e06af5c8318db5366ff0..56f4f712375ade70afd76525b80eeebe6247bb0f 100644 (file)
@@ -20,8 +20,8 @@
 #include <folly/futures/InlineExecutor.h>
 #include <folly/futures/Promise.h>
 #include <folly/portability/GFlags.h>
+#include <folly/portability/Semaphore.h>
 
-#include <semaphore.h>
 #include <vector>
 
 using namespace folly;
@@ -40,7 +40,7 @@ void someThens(size_t n) {
   }
 }
 
-} // anonymous namespace
+} // namespace
 
 BENCHMARK(constantFuture) {
   makeFuture(42);
@@ -94,18 +94,23 @@ BENCHMARK(no_contention) {
 
   BENCHMARK_SUSPEND {
     folly::Baton<> b1, b2;
-    for (auto& p : promises)
+    for (auto& p : promises) {
       futures.push_back(p.getFuture());
+    }
 
     consumer = std::thread([&]{
       b1.post();
-      for (auto& f : futures) f.then(incr<int>);
+      for (auto& f : futures) {
+        f.then(incr<int>);
+      }
     });
     consumer.join();
 
     producer = std::thread([&]{
       b2.post();
-      for (auto& p : promises) p.setValue(42);
+      for (auto& p : promises) {
+        p.setValue(42);
+      }
     });
 
     b1.wait();
@@ -125,8 +130,9 @@ BENCHMARK_RELATIVE(contention) {
 
   BENCHMARK_SUSPEND {
     folly::Baton<> b1, b2;
-    for (auto& p : promises)
+    for (auto& p : promises) {
       futures.push_back(p.getFuture());
+    }
 
     consumer = std::thread([&]{
       b1.post();
@@ -290,6 +296,44 @@ BENCHMARK_RELATIVE(throwWrappedAndCatchWrappedContended) {
   contend(throwWrappedAndCatchWrappedImpl);
 }
 
+BENCHMARK_DRAW_LINE();
+
+namespace {
+struct Bulky {
+  explicit Bulky(std::string message) : message_(message) {}
+  std::string message() & {
+    return message_;
+  }
+  std::string&& message() && {
+    return std::move(message_);
+  }
+
+ private:
+  std::string message_;
+  std::array<int, 1024> ints_;
+};
+} // anonymous namespace
+
+BENCHMARK(lvalue_get) {
+  BenchmarkSuspender suspender;
+  Optional<Future<Bulky>> future;
+  future = makeFuture(Bulky("Hello"));
+  suspender.dismissing([&] {
+    std::string message = future.value().get().message();
+    doNotOptimizeAway(message);
+  });
+}
+
+BENCHMARK_RELATIVE(rvalue_get) {
+  BenchmarkSuspender suspender;
+  Optional<Future<Bulky>> future;
+  future = makeFuture(Bulky("Hello"));
+  suspender.dismissing([&] {
+    std::string message = std::move(future.value()).get().message();
+    doNotOptimizeAway(message);
+  });
+}
+
 InlineExecutor exe;
 
 template <class T>