don't use assert in benchmarks. it gets stripped out in release mode.
authorEric Niebler <eniebler@fb.com>
Thu, 5 Jan 2017 21:48:28 +0000 (13:48 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 5 Jan 2017 22:03:03 +0000 (14:03 -0800)
Summary: Critical tests in benchmarks should not be in asserts since they will be stripped out in release mode, which is the only mode interesting for benchmarks.

Reviewed By: yfeldblum

Differential Revision: D4384411

fbshipit-source-id: 5237ab48f99ddcd2bce7a159fcf82900303efec2

folly/test/ExceptionWrapperBenchmark.cpp

index 0e4c8ea7bf5112af2fbd463edd80f36f88977c8c..16af2206bc03576970c0ae0b47c639a2de21f95c 100644 (file)
@@ -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,7 +109,6 @@ 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&) {
     }
   }
@@ -117,7 +120,6 @@ BENCHMARK_RELATIVE(exception_wrapper_create_and_throw, iters) {
     auto ew = folly::make_exception_wrapper<std::runtime_error>(e);
     try {
       ew.throwException();
-      assert(false);
     } 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,7 +149,6 @@ 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&) {
           }
         }
@@ -171,7 +173,6 @@ BENCHMARK_RELATIVE(exception_wrapper_create_and_throw_concurrent, iters) {
           auto ew = folly::make_exception_wrapper<std::runtime_error>(e);
           try {
             ew.throwException();
-            assert(false);
           } 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);
         }
       });
     }