Fix copyright lines for Bits.h and move BitsBenchmark.cpp
[folly.git] / folly / test / ExceptionWrapperBenchmark.cpp
index fbd72820c4cdce9010657462c114fb673bcd477d..dc52f5ce3e7510c3ce93f9b8add581b445550f97 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -36,7 +36,8 @@ BENCHMARK(exception_ptr_create_and_test, iters) {
   std::runtime_error e("payload");
   for (size_t i = 0; i < iters; ++i) {
     auto ep = std::make_exception_ptr(e);
-    assert(ep);
+    bool b = static_cast<bool>(ep);
+    folly::doNotOptimizeAway(b);
   }
 }
 
@@ -44,7 +45,8 @@ BENCHMARK_RELATIVE(exception_wrapper_create_and_test, iters) {
   std::runtime_error e("payload");
   for (size_t i = 0; i < iters; ++i) {
     auto ew = folly::make_exception_wrapper<std::runtime_error>(e);
-    assert(ew);
+    bool b = static_cast<bool>(ew);
+    folly::doNotOptimizeAway(b);
   }
 }
 
@@ -60,7 +62,8 @@ BENCHMARK(exception_ptr_create_and_test_concurrent, iters) {
         std::runtime_error e("payload");
         for (size_t i = 0; i < iters; ++i) {
           auto ep = std::make_exception_ptr(e);
-          assert(ep);
+          bool b = static_cast<bool>(ep);
+          folly::doNotOptimizeAway(b);
         }
       });
     }
@@ -81,7 +84,8 @@ BENCHMARK_RELATIVE(exception_wrapper_create_and_test_concurrent, iters) {
         std::runtime_error e("payload");
         for (size_t i = 0; i < iters; ++i) {
           auto ew = folly::make_exception_wrapper<std::runtime_error>(e);
-          assert(ew);
+          bool b = static_cast<bool>(ew);
+          folly::doNotOptimizeAway(b);
         }
       });
     }
@@ -105,8 +109,7 @@ BENCHMARK(exception_ptr_create_and_throw, iters) {
     auto ep = std::make_exception_ptr(e);
     try {
       std::rethrow_exception(ep);
-      assert(false);
-    } catch (std::runtime_error& e) {
+    } catch (std::runtime_error&) {
     }
   }
 }
@@ -116,9 +119,8 @@ BENCHMARK_RELATIVE(exception_wrapper_create_and_throw, iters) {
   for (size_t i = 0; i < iters; ++i) {
     auto ew = folly::make_exception_wrapper<std::runtime_error>(e);
     try {
-      ew.throwException();
-      assert(false);
-    } catch (std::runtime_error& e) {
+      ew.throw_exception();
+    } catch (std::runtime_error&) {
     }
   }
 }
@@ -127,7 +129,8 @@ BENCHMARK_RELATIVE(exception_wrapper_create_and_cast, iters) {
   std::runtime_error e("payload");
   for (size_t i = 0; i < iters; ++i) {
     auto ew = folly::make_exception_wrapper<std::runtime_error>(e);
-    assert(ew.is_compatible_with<std::runtime_error>());
+    bool b = ew.is_compatible_with<std::runtime_error>();
+    folly::doNotOptimizeAway(b);
   }
 }
 
@@ -146,8 +149,7 @@ BENCHMARK(exception_ptr_create_and_throw_concurrent, iters) {
           auto ep = std::make_exception_ptr(e);
           try {
             std::rethrow_exception(ep);
-            assert(false);
-          } catch (std::runtime_error& e) {
+          } catch (std::runtime_error&) {
           }
         }
       });
@@ -170,9 +172,8 @@ BENCHMARK_RELATIVE(exception_wrapper_create_and_throw_concurrent, iters) {
         for (size_t i = 0; i < iters; ++i) {
           auto ew = folly::make_exception_wrapper<std::runtime_error>(e);
           try {
-            ew.throwException();
-            assert(false);
-          } catch (std::runtime_error& e) {
+            ew.throw_exception();
+          } catch (std::runtime_error&) {
           }
         }
       });
@@ -194,7 +195,8 @@ BENCHMARK_RELATIVE(exception_wrapper_create_and_cast_concurrent, iters) {
         std::runtime_error e("payload");
         for (size_t i = 0; i < iters; ++i) {
           auto ew = folly::make_exception_wrapper<std::runtime_error>(e);
-          assert(ew.is_compatible_with<std::runtime_error>());
+          bool b = ew.is_compatible_with<std::runtime_error>();
+          folly::doNotOptimizeAway(b);
         }
       });
     }