update function_benchmark to test exception handling
authorAdam Simpkins <simpkins@fb.com>
Wed, 31 Oct 2012 19:29:04 +0000 (12:29 -0700)
committerJordan DeLong <jdelong@fb.com>
Sun, 16 Dec 2012 22:42:00 +0000 (14:42 -0800)
commit5196d1e2879db3000e260bccd110efc1d432ac74
treea04ecc36d1979c95baa86bf2c30cd74bdaf65ec9
parent5ec53c6ffeb49e5dedb929562822aaf78f835de5
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
folly/test/function_benchmark/main.cpp
folly/test/function_benchmark/test_functions.cpp
folly/test/function_benchmark/test_functions.h