30 "Number of threads to run concurrency " 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);
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);
58 BENCHMARK(exception_ptr_create_and_test_concurrent, iters) {
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) {
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) {
112 std::runtime_error e(
"payload");
113 for (
size_t i = 0;
i < iters; ++
i) {
114 auto ep = std::make_exception_ptr(e);
116 std::rethrow_exception(
ep);
117 }
catch (std::runtime_error&) {
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&) {
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>();
144 BENCHMARK(exception_ptr_create_and_throw_concurrent, iters) {
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);
156 std::rethrow_exception(
ep);
157 }
catch (std::runtime_error&) {
164 for (
auto&
t : 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) {
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) {
218 gflags::ParseCommandLineFlags(&argc, &argv,
true);
BENCHMARK(exception_ptr_create_and_test, iters)
BENCHMARK_RELATIVE(exception_wrapper_create_and_test, iters)
#define BENCHMARK_SUSPEND
int main(int argc, char *argv[])
std::vector< std::thread::id > threads
DEFINE_int32(num_threads, 32,"Number of threads to run concurrency ""benchmarks")
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type