ADT
ast-experimental
enum
forall-pointer-decay
jacob/cs343-translation
new-ast-unique-expr
pthread-emulation
qualifiedEnum
Last change
on this file since 0a061c0 was 866cad3, checked in by Andrew Beach <ajbeach@…>, 4 years ago |
Changed how the cross exception benchmarks prevent optimization. Hopefully this will work on more platforms.
|
-
Property mode
set to
100644
|
File size:
872 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;
|
---|
[866cad3] | 13 | volatile 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 {
|
---|
[866cad3] | 21 | asm volatile ("# try block");
|
---|
[54651005] | 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.