- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/andrew_beach_MMath/code/cond-catch.cpp
r54651005 rf79ee0d 4 4 #include <exception> 5 5 #include <iostream> 6 #include <iomanip> 6 7 8 using namespace std; 7 9 using namespace std::chrono; 8 10 … … 10 12 11 13 bool should_catch = false; 12 13 void throw_exception() {14 throw EmptyException();15 }16 17 void cond_catch() {18 try {19 throw_exception();20 } catch (EmptyException & exc) {21 if (!should_catch) {22 throw;23 }24 asm volatile ("# catch block (conditional)");25 }26 }27 14 28 15 int main(int argc, char * argv[]) { … … 38 25 for (unsigned int count = 0 ; count < times ; ++count) { 39 26 try { 40 cond_catch(); 27 try { 28 throw EmptyException(); 29 } catch (EmptyException & exc) { 30 if (!should_catch) { 31 throw; 32 } 33 asm volatile ("# catch block (conditional)"); 34 } 41 35 } catch (EmptyException &) { 42 36 asm volatile ("# catch block (unconditional)"); … … 45 39 time_point<steady_clock> end_time = steady_clock::now(); 46 40 nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time); 47 std::cout << "Run-Time (ns): " << duration.count() << std::endl;41 cout << "Run-Time (s): " << fixed << setprecision(1) << duration.count() / 1'000'000'000. << endl; 48 42 }
Note: See TracChangeset
for help on using the changeset viewer.