source: doc/theses/andrew_beach_MMath/code/cross-catch.cpp @ e4da70b

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since e4da70b was 866cad3, checked in by Andrew Beach <ajbeach@…>, 3 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
Line 
1// Cross a Try Statement with a Termination Handler
2#include <chrono>
3#include <cstdlib>
4#include <exception>
5#include <iostream>
6
7using namespace std::chrono;
8
9struct NotRaisedException : public std::exception {};
10
11int main(int argc, char * argv[]) {
12        unsigned int times = 1;
13        volatile bool should_throw = false;
14        if (1 < argc) {
15                times = strtol(argv[1], nullptr, 10);
16        }
17
18        time_point<steady_clock> start_time = steady_clock::now();
19        for (unsigned int count = 0 ; count < times ; ++count) {
20                try {
21                        asm volatile ("# try block");
22                        if (should_throw) {
23                                throw NotRaisedException();
24                        }
25                } catch (NotRaisedException &) {
26                        asm volatile ("# catch block");
27                }
28        }
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;
32}
Note: See TracBrowser for help on using the repository browser.