27 using namespace folly;
36 void someThens(
size_t n) {
37 auto f = makeFuture<int>(42);
38 for (
size_t i = 0;
i < n;
i++) {
91 std::vector<Promise<int>> promises(10000);
92 std::vector<Future<int>>
futures;
93 std::thread producer, consumer;
97 for (
auto& p : promises) {
98 futures.push_back(p.getFuture());
101 consumer = std::thread([&] {
103 for (
auto&
f : futures) {
109 producer = std::thread([&] {
111 for (
auto& p : promises) {
125 std::vector<Promise<int>> promises(10000);
126 std::vector<Future<int>>
futures;
127 std::thread producer, consumer;
129 sem_init(&sem, 0, 0);
133 for (
auto& p : promises) {
134 futures.push_back(p.getFuture());
137 consumer = std::thread([&] {
139 for (
auto&
f : futures) {
145 producer = std::thread([&] {
147 for (
auto& p : promises) {
178 .then([](
Try<Unit>&&) {
throw std::runtime_error(
"oh no"); })
182 }
catch (
const std::runtime_error& e) {
198 .then([](
Try<Unit>&&) {
throw std::runtime_error(
"oh no"); })
200 auto caught =
t.withException<std::runtime_error>(
201 [](
const std::runtime_error& ) {
212 return makeFuture<Unit>(std::runtime_error(
"oh no"));
217 }
catch (
const std::runtime_error& e) {
229 return makeFuture<Unit>(std::runtime_error(
"oh no"));
232 auto caught =
t.withException<std::runtime_error>(
233 [](
const std::runtime_error& ) {
244 const int iters = 1000;
245 pthread_barrier_t barrier;
246 pthread_barrier_init(&barrier,
nullptr, N + 1);
247 std::vector<std::thread>
threads;
248 for (
int i = 0;
i < N;
i++) {
249 threads.push_back(std::thread([&]() {
250 pthread_barrier_wait(&barrier);
251 for (
int j = 0; j < iters; j++) {
256 pthread_barrier_wait(&barrier);
258 for (
auto&
t : threads) {
262 pthread_barrier_destroy(&barrier);
313 std::array<int, 1024> ints_;
354 std::vector<Future<T>> fs;
355 for (
auto i = 0;
i < 10;
i++) {
356 fs.push_back(fGen<T>());
378 complexBenchmark<Unit>();
382 complexBenchmark<Blob<4>>();
386 complexBenchmark<Blob<8>>();
390 complexBenchmark<Blob<64>>();
394 complexBenchmark<Blob<128>>();
398 complexBenchmark<Blob<256>>();
402 complexBenchmark<Blob<512>>();
406 complexBenchmark<Blob<1024>>();
410 complexBenchmark<Blob<2048>>();
414 complexBenchmark<Blob<4096>>();
418 gflags::ParseCommandLineFlags(&argc, &argv,
true);
int main(int argc, char **argv)
#define BENCHMARK_SUSPEND
constexpr detail::Map< Move > move
—— Concurrent Priority Queue Implementation ——
std::vector< Future< Result > > map(It first, It last, F func)
std::vector< std::thread::id > threads
FOLLY_ALWAYS_INLINE void wait(const WaitOptions &opt=wait_options()) noexcept
void throwAndCatchWrappedImpl()
Future< std::pair< size_t, Try< typename std::iterator_traits< InputIterator >::value_type::value_type > > > collectAny(InputIterator first, InputIterator last)
Future< std::tuple< Try< typename remove_cvref_t< Fs >::value_type >... > > collectAll(Fs &&...fs)
BENCHMARK_RELATIVE(promiseAndFuture)
void throwWrappedAndCatchWrappedImpl()
void contend(void(*func)())
std::enable_if< std::is_same< Unit, B >::value, void >::type setValue()
Future< std::vector< typename std::iterator_traits< InputIterator >::value_type::value_type > > collect(InputIterator first, InputIterator last)
BENCHMARK(fbFollyGlobalBenchmarkBaseline)
auto dismissing(F f) -> invoke_result_t< F >
void throwWrappedAndCatchImpl()
auto via(Executor *x, Func &&func) -> Future< typename isFutureOrSemiFuture< decltype(std::declval< Func >()())>::Inner >
FOLLY_CPP14_CONSTEXPR const Value & value() const &
std::vector< Future< T > > fsGen()
Future< typename std::decay< T >::type > makeFuture(T &&t)
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type