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

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 9f77301 was ee23a8d, checked in by Andrew Beach <ajbeach@…>, 3 years ago

Added duration information (in nanoseconds) to EHM benchmarks.

  • Property mode set to 100644
File size: 727 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        if (1 < argc) {
14                times = strtol(argv[1], nullptr, 10);
15        }
16
17        time_point<steady_clock> start_time = steady_clock::now();
18        for (unsigned int count = 0 ; count < times ; ++count) {
19                try {
20                        // ...
21                } catch (NotRaisedException &) {
22                        // ...
23                }
24        }
25        time_point<steady_clock> end_time = steady_clock::now();
26        nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time);
27        std::cout << "Run-Time (ns): " << duration.count() << std::endl;
28}
Note: See TracBrowser for help on using the repository browser.