Last change
on this file since 562ccf9 was
f79ee0d,
checked in by Peter A. Buhr <pabuhr@…>, 3 years ago
|
update exception benchmarks
|
-
Property mode set to
100644
|
File size:
946 bytes
|
Line | |
---|
1 | // Cross a Try Statement with a Termination Handler |
---|
2 | #include <chrono> |
---|
3 | #include <cstdlib> |
---|
4 | #include <exception> |
---|
5 | #include <iostream> |
---|
6 | #include <iomanip> |
---|
7 | |
---|
8 | using namespace std; |
---|
9 | using namespace std::chrono; |
---|
10 | |
---|
11 | struct NotRaisedException : public std::exception {}; |
---|
12 | |
---|
13 | int main(int argc, char * argv[]) { |
---|
14 | unsigned int times = 1; |
---|
15 | volatile bool should_throw = false; |
---|
16 | if (1 < argc) { |
---|
17 | times = strtol(argv[1], nullptr, 10); |
---|
18 | } |
---|
19 | |
---|
20 | time_point<steady_clock> start_time = steady_clock::now(); |
---|
21 | for (unsigned int count = 0 ; count < times ; ++count) { |
---|
22 | try { |
---|
23 | asm volatile ("# try block"); |
---|
24 | if (should_throw) { |
---|
25 | throw NotRaisedException(); |
---|
26 | } |
---|
27 | } catch (NotRaisedException &) { |
---|
28 | asm volatile ("# catch block"); |
---|
29 | } |
---|
30 | } |
---|
31 | time_point<steady_clock> end_time = steady_clock::now(); |
---|
32 | nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time); |
---|
33 | cout << "Run-Time (s): " << fixed << setprecision(1) << duration.count() / 1'000'000'000. << endl; |
---|
34 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.