#include <folly/ExceptionWrapper.h>
#include <atomic>
#include <exception>
#include <stdexcept>
#include <thread>
#include <vector>
#include <folly/Benchmark.h>
#include <folly/portability/GFlags.h>
Go to the source code of this file.
|
| DEFINE_int32 (num_threads, 32,"Number of threads to run concurrency ""benchmarks") |
|
| BENCHMARK (exception_ptr_create_and_test, iters) |
|
| BENCHMARK_RELATIVE (exception_wrapper_create_and_test, iters) |
|
| BENCHMARK_DRAW_LINE () |
|
| BENCHMARK (exception_ptr_create_and_test_concurrent, iters) |
|
| BENCHMARK_RELATIVE (exception_wrapper_create_and_test_concurrent, iters) |
|
| BENCHMARK (exception_ptr_create_and_throw, iters) |
|
| BENCHMARK_RELATIVE (exception_wrapper_create_and_throw, iters) |
|
| BENCHMARK_RELATIVE (exception_wrapper_create_and_cast, iters) |
|
| BENCHMARK (exception_ptr_create_and_throw_concurrent, iters) |
|
| BENCHMARK_RELATIVE (exception_wrapper_create_and_throw_concurrent, iters) |
|
| BENCHMARK_RELATIVE (exception_wrapper_create_and_cast_concurrent, iters) |
|
int | main (int argc, char *argv[]) |
|
BENCHMARK |
( |
exception_ptr_create_and_test |
, |
|
|
iters |
|
|
) |
| |
Definition at line 38 of file ExceptionWrapperBenchmark.cpp.
References b, folly::doNotOptimizeAway(), and i.
39 std::runtime_error e(
"payload");
40 for (
size_t i = 0;
i < iters; ++
i) {
41 auto ep = std::make_exception_ptr(e);
42 bool b =
static_cast<bool>(
ep);
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
BENCHMARK |
( |
exception_ptr_create_and_test_concurrent |
, |
|
|
iters |
|
|
) |
| |
Definition at line 58 of file ExceptionWrapperBenchmark.cpp.
References b, BENCHMARK_SUSPEND, folly::doNotOptimizeAway(), i, folly::pushmi::detail::t, and threads.
59 std::atomic<bool> go(
false);
60 std::vector<std::thread>
threads;
62 for (
int t = 0;
t < FLAGS_num_threads; ++
t) {
63 threads.emplace_back([&go, iters] {
66 std::runtime_error e(
"payload");
67 for (
size_t i = 0;
i < iters; ++
i) {
68 auto ep = std::make_exception_ptr(e);
69 bool b =
static_cast<bool>(
ep);
76 for (
auto&
t : threads) {
#define BENCHMARK_SUSPEND
std::vector< std::thread::id > threads
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
BENCHMARK |
( |
exception_ptr_create_and_throw |
, |
|
|
iters |
|
|
) |
| |
Definition at line 111 of file ExceptionWrapperBenchmark.cpp.
References i.
112 std::runtime_error e(
"payload");
113 for (
size_t i = 0;
i < iters; ++
i) {
114 auto ep = std::make_exception_ptr(e);
117 }
catch (std::runtime_error&) {
void rethrow_exception(std::exception_ptr ep)
BENCHMARK |
( |
exception_ptr_create_and_throw_concurrent |
, |
|
|
iters |
|
|
) |
| |
Definition at line 144 of file ExceptionWrapperBenchmark.cpp.
References BENCHMARK_SUSPEND, i, folly::pushmi::detail::t, and threads.
145 std::atomic<bool> go(
false);
146 std::vector<std::thread>
threads;
148 for (
int t = 0;
t < FLAGS_num_threads; ++
t) {
149 threads.emplace_back([&go, iters] {
152 std::runtime_error e(
"payload");
153 for (
size_t i = 0;
i < iters; ++
i) {
154 auto ep = std::make_exception_ptr(e);
157 }
catch (std::runtime_error&) {
164 for (
auto&
t : threads) {
void rethrow_exception(std::exception_ptr ep)
#define BENCHMARK_SUSPEND
std::vector< std::thread::id > threads
BENCHMARK_RELATIVE |
( |
exception_wrapper_create_and_test |
, |
|
|
iters |
|
|
) |
| |
Definition at line 47 of file ExceptionWrapperBenchmark.cpp.
References b, BENCHMARK_DRAW_LINE(), folly::doNotOptimizeAway(), and i.
48 std::runtime_error e(
"payload");
49 for (
size_t i = 0;
i < iters; ++
i) {
50 auto ew = folly::make_exception_wrapper<std::runtime_error>(e);
51 bool b =
static_cast<bool>(ew);
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
BENCHMARK_RELATIVE |
( |
exception_wrapper_create_and_test_concurrent |
, |
|
|
iters |
|
|
) |
| |
Definition at line 81 of file ExceptionWrapperBenchmark.cpp.
References b, BENCHMARK_DRAW_LINE(), BENCHMARK_SUSPEND, folly::doNotOptimizeAway(), i, folly::pushmi::detail::t, and threads.
82 std::atomic<bool> go(
false);
83 std::vector<std::thread>
threads;
85 for (
int t = 0;
t < FLAGS_num_threads; ++
t) {
86 threads.emplace_back([&go, iters] {
89 std::runtime_error e(
"payload");
90 for (
size_t i = 0;
i < iters; ++
i) {
91 auto ew = folly::make_exception_wrapper<std::runtime_error>(e);
92 bool b =
static_cast<bool>(ew);
99 for (
auto&
t : threads) {
#define BENCHMARK_SUSPEND
std::vector< std::thread::id > threads
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
BENCHMARK_RELATIVE |
( |
exception_wrapper_create_and_throw |
, |
|
|
iters |
|
|
) |
| |
Definition at line 122 of file ExceptionWrapperBenchmark.cpp.
References i.
123 std::runtime_error e(
"payload");
124 for (
size_t i = 0;
i < iters; ++
i) {
125 auto ew = folly::make_exception_wrapper<std::runtime_error>(e);
127 ew.throw_exception();
128 }
catch (std::runtime_error&) {
BENCHMARK_RELATIVE |
( |
exception_wrapper_create_and_cast |
, |
|
|
iters |
|
|
) |
| |
Definition at line 133 of file ExceptionWrapperBenchmark.cpp.
References b, BENCHMARK_DRAW_LINE(), folly::doNotOptimizeAway(), and i.
134 std::runtime_error e(
"payload");
135 for (
size_t i = 0;
i < iters; ++
i) {
136 auto ew = folly::make_exception_wrapper<std::runtime_error>(e);
137 bool b = ew.is_compatible_with<std::runtime_error>();
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
BENCHMARK_RELATIVE |
( |
exception_wrapper_create_and_throw_concurrent |
, |
|
|
iters |
|
|
) |
| |
Definition at line 169 of file ExceptionWrapperBenchmark.cpp.
References BENCHMARK_SUSPEND, i, folly::pushmi::detail::t, and threads.
170 std::atomic<bool> go(
false);
171 std::vector<std::thread>
threads;
173 for (
int t = 0;
t < FLAGS_num_threads; ++
t) {
174 threads.emplace_back([&go, iters] {
177 std::runtime_error e(
"payload");
178 for (
size_t i = 0;
i < iters; ++
i) {
179 auto ew = folly::make_exception_wrapper<std::runtime_error>(e);
181 ew.throw_exception();
182 }
catch (std::runtime_error&) {
189 for (
auto&
t : threads) {
#define BENCHMARK_SUSPEND
std::vector< std::thread::id > threads
BENCHMARK_RELATIVE |
( |
exception_wrapper_create_and_cast_concurrent |
, |
|
|
iters |
|
|
) |
| |
Definition at line 194 of file ExceptionWrapperBenchmark.cpp.
References b, BENCHMARK_SUSPEND, folly::doNotOptimizeAway(), i, folly::pushmi::detail::t, and threads.
195 std::atomic<bool> go(
false);
196 std::vector<std::thread>
threads;
198 for (
int t = 0;
t < FLAGS_num_threads; ++
t) {
199 threads.emplace_back([&go, iters] {
202 std::runtime_error e(
"payload");
203 for (
size_t i = 0;
i < iters; ++
i) {
204 auto ew = folly::make_exception_wrapper<std::runtime_error>(e);
205 bool b = ew.is_compatible_with<std::runtime_error>();
212 for (
auto&
t : threads) {
#define BENCHMARK_SUSPEND
std::vector< std::thread::id > threads
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
DEFINE_int32 |
( |
num_threads |
, |
|
|
32 |
, |
|
|
"Number of threads to run concurrency ""benchmarks" |
|
|
) |
| |
int main |
( |
int |
argc, |
|
|
char * |
argv[] |
|
) |
| |