ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since 54651005 was
54651005,
checked in by Andrew Beach <ajbeach@…>, 3 years ago
|
Added asm statements to the exception benchmarks to prevent unwanted optimizations.
|
-
Property mode set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[ea593a3] | 1 | // Throw Across Other Handler |
---|
[ee23a8d] | 2 | #include <chrono> |
---|
[ea593a3] | 3 | #include <cstdlib> |
---|
[ee23a8d] | 4 | #include <exception> |
---|
| 5 | #include <iostream> |
---|
| 6 | |
---|
| 7 | using namespace std::chrono; |
---|
[ea593a3] | 8 | |
---|
| 9 | struct EmptyException : public std::exception {}; |
---|
| 10 | |
---|
| 11 | struct NotRaisedException {}; |
---|
| 12 | |
---|
| 13 | void unwind_other(unsigned int frames) { |
---|
| 14 | if (frames) { |
---|
| 15 | try { |
---|
| 16 | unwind_other(frames - 1); |
---|
| 17 | } catch (NotRaisedException &) { |
---|
[54651005] | 18 | asm volatile ("# catch block (stack)"); |
---|
[ea593a3] | 19 | } |
---|
| 20 | } else { |
---|
| 21 | throw (EmptyException){}; |
---|
| 22 | } |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | int main(int argc, char * argv[]) { |
---|
| 26 | unsigned int times = 1; |
---|
| 27 | unsigned int total_frames = 1; |
---|
[ee23a8d] | 28 | if (1 < argc) { |
---|
[ea593a3] | 29 | times = strtol(argv[1], nullptr, 10); |
---|
| 30 | } |
---|
[ee23a8d] | 31 | if (2 < argc) { |
---|
[ea593a3] | 32 | total_frames = strtol(argv[2], nullptr, 10); |
---|
| 33 | } |
---|
| 34 | |
---|
[ee23a8d] | 35 | time_point<steady_clock> start_time = steady_clock::now(); |
---|
[ea593a3] | 36 | for (int count = 0 ; count < times ; ++count) { |
---|
| 37 | try { |
---|
| 38 | unwind_other(total_frames); |
---|
| 39 | } catch (EmptyException &) { |
---|
[54651005] | 40 | asm volatile ("# catch block (base)"); |
---|
[ea593a3] | 41 | } |
---|
| 42 | } |
---|
[ee23a8d] | 43 | time_point<steady_clock> end_time = steady_clock::now(); |
---|
| 44 | nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time); |
---|
| 45 | std::cout << "Run-Time (ns): " << duration.count() << std::endl; |
---|
[ea593a3] | 46 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.