#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;
}
}
-} // anonymous namespace
+} // namespace
BENCHMARK(constantFuture) {
makeFuture(42);
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();
BENCHMARK_SUSPEND {
folly::Baton<> b1, b2;
- for (auto& p : promises)
+ for (auto& p : promises) {
futures.push_back(p.getFuture());
+ }
consumer = std::thread([&]{
b1.post();
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>