update function_benchmark to test exception handling
Summary: Add benchmarks for throwing an exception versus returning std::exception_ptr or other types of return values. Throwing an exception is very expensive. Calling std::make_exception_ptr() without ever throwing is nearly as bad. The exc_ptr_param_return tests were the ones I was most interested in. (Accepting a std::exception_ptr* argument so the caller can indicate if they want to receive an exception or not.) This is fast if the caller doesn't care about the exception value, but very slow if an error occurs and an exception_ptr is required. Test Plan: ====================================================================== folly/test/function_benchmark/main.cpp relative time/iter iters/s ====================================================================== throw_exception 3.90us 256.25K catch_no_exception 1.88ns 533.25M return_exc_ptr 2.79us 357.85K exc_ptr_param_return 2.83us 353.25K exc_ptr_param_return_null 2.25ns 444.38M return_string 69.39ns 14.41M return_string_noexcept 69.39ns 14.41M return_code 1.50ns 666.54M return_code_noexcept 1.50ns 666.54M Reviewed By: rajat@fb.com FB internal diff: D616474
Showing
Please register or sign in to comment