ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since a5a6a1a8 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:
886 bytes
|
Rev | Line | |
---|
[ea593a3] | 1 | // Cross a Try Statement with a Termination 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 NotRaisedException : public std::exception {}; |
---|
| 10 | |
---|
| 11 | int main(int argc, char * argv[]) { |
---|
| 12 | unsigned int times = 1; |
---|
[54651005] | 13 | bool should_throw = false; |
---|
[ee23a8d] | 14 | if (1 < argc) { |
---|
[ea593a3] | 15 | times = strtol(argv[1], nullptr, 10); |
---|
| 16 | } |
---|
| 17 | |
---|
[ee23a8d] | 18 | time_point<steady_clock> start_time = steady_clock::now(); |
---|
[ea593a3] | 19 | for (unsigned int count = 0 ; count < times ; ++count) { |
---|
| 20 | try { |
---|
[54651005] | 21 | asm volatile ("# try block" : "=rm" (should_throw)); |
---|
| 22 | if (should_throw) { |
---|
| 23 | throw NotRaisedException(); |
---|
| 24 | } |
---|
[ea593a3] | 25 | } catch (NotRaisedException &) { |
---|
[54651005] | 26 | asm volatile ("# catch block"); |
---|
[ea593a3] | 27 | } |
---|
| 28 | } |
---|
[ee23a8d] | 29 | time_point<steady_clock> end_time = steady_clock::now(); |
---|
| 30 | nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time); |
---|
| 31 | std::cout << "Run-Time (ns): " << duration.count() << std::endl; |
---|
[ea593a3] | 32 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.