From: Eric Niebler Date: Thu, 5 Jan 2017 21:48:28 +0000 (-0800) Subject: don't use assert in benchmarks. it gets stripped out in release mode. X-Git-Tag: v2017.03.06.00~132 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=7ea05dfbed154482798ec397d8d253da599d115d;p=folly.git don't use assert in benchmarks. it gets stripped out in release mode. 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 --- diff --git a/folly/test/ExceptionWrapperBenchmark.cpp b/folly/test/ExceptionWrapperBenchmark.cpp index 0e4c8ea7..16af2206 100644 --- a/folly/test/ExceptionWrapperBenchmark.cpp +++ b/folly/test/ExceptionWrapperBenchmark.cpp @@ -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(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(e); - assert(ew); + bool b = static_cast(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(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(e); - assert(ew); + bool b = static_cast(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(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(e); - assert(ew.is_compatible_with()); + bool b = ew.is_compatible_with(); + 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(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(e); - assert(ew.is_compatible_with()); + bool b = ew.is_compatible_with(); + folly::doNotOptimizeAway(b); } }); }