proxygen
ExceptionWrapperBenchmark.cpp File Reference
#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.

Functions

 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[])
 

Function Documentation

BENCHMARK ( exception_ptr_create_and_test  ,
iters   
)

Definition at line 38 of file ExceptionWrapperBenchmark.cpp.

References b, folly::doNotOptimizeAway(), and i.

38  {
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);
44  }
45 }
char b
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
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.

58  {
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] {
64  while (!go) {
65  }
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);
71  }
72  });
73  }
74  }
75  go.store(true);
76  for (auto& t : threads) {
77  t.join();
78  }
79 }
char b
#define BENCHMARK_SUSPEND
Definition: Benchmark.h:576
std::vector< std::thread::id > threads
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( exception_ptr_create_and_throw  ,
iters   
)

Definition at line 111 of file ExceptionWrapperBenchmark.cpp.

References i.

111  {
112  std::runtime_error e("payload");
113  for (size_t i = 0; i < iters; ++i) {
114  auto ep = std::make_exception_ptr(e);
115  try {
117  } catch (std::runtime_error&) {
118  }
119  }
120 }
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.

144  {
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] {
150  while (!go) {
151  }
152  std::runtime_error e("payload");
153  for (size_t i = 0; i < iters; ++i) {
154  auto ep = std::make_exception_ptr(e);
155  try {
157  } catch (std::runtime_error&) {
158  }
159  }
160  });
161  }
162  }
163  go.store(true);
164  for (auto& t : threads) {
165  t.join();
166  }
167 }
void rethrow_exception(std::exception_ptr ep)
#define BENCHMARK_SUSPEND
Definition: Benchmark.h:576
std::vector< std::thread::id > threads
BENCHMARK_DRAW_LINE ( )

Referenced by BENCHMARK_RELATIVE().

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.

47  {
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);
53  }
54 }
char b
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
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.

81  {
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] {
87  while (!go) {
88  }
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);
94  }
95  });
96  }
97  }
98  go.store(true);
99  for (auto& t : threads) {
100  t.join();
101  }
102 }
char b
#define BENCHMARK_SUSPEND
Definition: Benchmark.h:576
std::vector< std::thread::id > threads
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK_RELATIVE ( exception_wrapper_create_and_throw  ,
iters   
)

Definition at line 122 of file ExceptionWrapperBenchmark.cpp.

References i.

122  {
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);
126  try {
127  ew.throw_exception();
128  } catch (std::runtime_error&) {
129  }
130  }
131 }
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.

133  {
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>();
139  }
140 }
char b
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
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.

169  {
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] {
175  while (!go) {
176  }
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);
180  try {
181  ew.throw_exception();
182  } catch (std::runtime_error&) {
183  }
184  }
185  });
186  }
187  }
188  go.store(true);
189  for (auto& t : threads) {
190  t.join();
191  }
192 }
#define BENCHMARK_SUSPEND
Definition: Benchmark.h:576
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.

194  {
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] {
200  while (!go) {
201  }
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>();
207  }
208  });
209  }
210  }
211  go.store(true);
212  for (auto& t : threads) {
213  t.join();
214  }
215 }
char b
#define BENCHMARK_SUSPEND
Definition: Benchmark.h:576
std::vector< std::thread::id > threads
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
DEFINE_int32 ( num_threads  ,
32  ,
"Number of threads to run concurrency ""benchmarks"   
)
int main ( int  argc,
char *  argv[] 
)

Definition at line 217 of file ExceptionWrapperBenchmark.cpp.

References folly::runBenchmarks().

217  {
218  gflags::ParseCommandLineFlags(&argc, &argv, true);
220  return 0;
221 }
void runBenchmarks()
Definition: Benchmark.cpp:456
char ** argv