Commit 0cb09568 authored by Lee Howes's avatar Lee Howes Committed by Facebook Github Bot

Add benchmark for inline continuations:

Summary:
Adds a benchmark to show the benefit of running work inline.

Dev:
| fourThensOnThread | 2.15% | 245.01us | 4.08K |
| fourThensOnThreadInline | 2.36% | 223.51us | 4.47K |
| hundredThensOnThread | 0.67% | 783.54us | 1.28K |
| hundredThensOnThreadInline | 0.88% |  595.24us | 1.68K |

Opt:
| fourThensOnThread                                |   0.18% |    70.37us  |  14.21K |
| fourThensOnThreadInline                          |   0.26%  |   50.11us   | 19.96K |
| hundredThensOnThread            | 0.18% | 72.54us | 13.79K |
| hundredThensOnThreadInline | 0.21%  | 64.79us | 15.43K |

Reviewed By: yfeldblum

Differential Revision: D15319231

fbshipit-source-id: 978c26538d89de15e76eb69bf20c1129b210a442
parent 9baf6c88
......@@ -18,6 +18,7 @@
#include <folly/executors/InlineExecutor.h>
#include <folly/futures/Future.h>
#include <folly/futures/Promise.h>
#include <folly/futures/test/TestExecutor.h>
#include <folly/portability/GFlags.h>
#include <folly/portability/Semaphore.h>
#include <folly/synchronization/Baton.h>
......@@ -33,11 +34,29 @@ T incr(Try<T>&& t) {
return t.value() + 1;
}
void someThens(size_t n) {
auto f = makeFuture<int>(42);
Future<int> thens(Future<int> f, size_t n, bool runInline = false) {
for (size_t i = 0; i < n; i++) {
f = std::move(f).then(incr<int>);
if (runInline) {
f = std::move(f).thenInline(incr<int>);
} else {
f = std::move(f).then(incr<int>);
}
}
return f;
}
void someThens(size_t n) {
auto f = makeFuture<int>(42);
f = thens(std::move(f), n);
}
void someThensOnThread(size_t n, bool runInline = false) {
auto executor = std::make_unique<TestExecutor>(1);
auto f = makeFuture<int>(42).via(executor.get());
f = thens(std::move(f), n / 2, runInline);
f = thens(std::move(f), 1, false);
f = thens(std::move(f), n / 2, runInline);
f.wait();
}
} // namespace
......@@ -82,6 +101,28 @@ BENCHMARK_RELATIVE(hundredThens) {
someThens(100);
}
BENCHMARK_DRAW_LINE();
// look for >= 25% relative
BENCHMARK_RELATIVE(fourThensOnThread) {
someThensOnThread(4);
}
// look for >= 25% relative
BENCHMARK_RELATIVE(fourThensOnThreadInline) {
someThensOnThread(4, true);
}
// look for >= 1% relative
BENCHMARK_RELATIVE(hundredThensOnThread) {
someThensOnThread(100);
}
// look for >= 1% relative
BENCHMARK_RELATIVE(hundredThensOnThreadInline) {
someThensOnThread(100, true);
}
// Lock contention. Although in practice fulfills tend to be temporally
// separate from then()s, still sometimes they will be concurrent. So the
// higher this number is, the better.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment