Benchmark a realistic common use
authorPhil Willoughby <philwill@fb.com>
Tue, 19 Sep 2017 20:57:36 +0000 (13:57 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Tue, 19 Sep 2017 21:05:05 +0000 (14:05 -0700)
Summary:
We didn't previously benchmark the performance of `get()`, which was a strange
omission.

Reviewed By: akrieger

Differential Revision: D5863567

fbshipit-source-id: 468b249da9120fcb84f3303ac5e2157761b6369d

folly/futures/test/Benchmark.cpp

index f6d838d8ffa80aa4498bd7b7d89815064f2db263..770a830ee1acd620adb94db806930954296442f0 100644 (file)
@@ -290,6 +290,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>