fork download
  1. #include <iostream>
  2. #include <chrono>
  3. #include <limits>
  4. using namespace std;
  5. using namespace std::chrono;
  6.  
  7. bool func_errcode(int const& val) {
  8. if(val == 100000000) return true;
  9. else return false;
  10. }
  11.  
  12. void func_exception(int & val) {
  13. if(val == 100000003) val = 10; //throw(true);
  14. }
  15.  
  16.  
  17. int main() {
  18. int i = 0;
  19.  
  20. auto t1 = high_resolution_clock::now();
  21. for(i = 0; i <= 100000001; ++i) {
  22. if(func_errcode(i)) break;
  23. }
  24. auto t2 = high_resolution_clock::now();
  25. std::cout << i << " Return error code: " << duration_cast<duration<double>>(t2 - t1).count() << " sec" << std::endl;
  26.  
  27.  
  28. t1 = high_resolution_clock::now();
  29. //try
  30. {
  31. for(i = 0; i <= 100000001; ++i) {
  32. func_exception(i);
  33. }
  34. }
  35. //catch(...)
  36. {}
  37. t2 = high_resolution_clock::now();
  38. std::cout << i << " Exception catch: " << duration_cast<duration<double>>(t2 - t1).count() << " sec" << std::endl;
  39.  
  40. int b; cin >> b;
  41. return 0;
  42. }
Success #stdin #stdout 0s 3344KB
stdin
Standard input is empty
stdout
100000000 Return error code: 3.06e-07 sec
100000002 Exception catch: 1.83e-07 sec