From 3619b401a7d7e2f1a3454ad04639831f8a2c224b Mon Sep 17 00:00:00 2001 From: Phil Willoughby Date: Tue, 19 Sep 2017 13:57:36 -0700 Subject: [PATCH] Benchmark a realistic common use 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 | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/folly/futures/test/Benchmark.cpp b/folly/futures/test/Benchmark.cpp index f6d838d8..770a830e 100644 --- a/folly/futures/test/Benchmark.cpp +++ b/folly/futures/test/Benchmark.cpp @@ -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 ints_; +}; +} // anonymous namespace + +BENCHMARK(lvalue_get) { + BenchmarkSuspender suspender; + Optional> future; + future = makeFuture(Bulky("Hello")); + suspender.dismissing([&] { + std::string message = future.value().get().message(); + doNotOptimizeAway(message); + }); +} + +BENCHMARK_RELATIVE(rvalue_get) { + BenchmarkSuspender suspender; + Optional> future; + future = makeFuture(Bulky("Hello")); + suspender.dismissing([&] { + std::string message = std::move(future.value()).get().message(); + doNotOptimizeAway(message); + }); +} + InlineExecutor exe; template -- 2.34.1