ADTast-experimentalenumpthread-emulationqualifiedEnum
Last change
on this file since 41870a5 was
f79ee0d,
checked in by Peter A. Buhr <pabuhr@…>, 3 years ago
|
update exception benchmarks
|
-
Property mode set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | // Throw Across Other 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 EmptyException : public std::exception {}; |
---|
12 | |
---|
13 | struct NotRaisedException {}; |
---|
14 | |
---|
15 | void unwind_other(unsigned int frames) { |
---|
16 | if (frames) { |
---|
17 | try { |
---|
18 | unwind_other(frames - 1); |
---|
19 | } catch (NotRaisedException &) { |
---|
20 | asm volatile ("# catch block (stack)"); |
---|
21 | } |
---|
22 | } else { |
---|
23 | throw (EmptyException){}; |
---|
24 | } |
---|
25 | } |
---|
26 | |
---|
27 | int main(int argc, char * argv[]) { |
---|
28 | unsigned int times = 1; |
---|
29 | unsigned int total_frames = 1; |
---|
30 | if (1 < argc) { |
---|
31 | times = strtol(argv[1], nullptr, 10); |
---|
32 | } |
---|
33 | if (2 < argc) { |
---|
34 | total_frames = strtol(argv[2], nullptr, 10); |
---|
35 | } |
---|
36 | |
---|
37 | time_point<steady_clock> start_time = steady_clock::now(); |
---|
38 | for (int count = 0 ; count < times ; ++count) { |
---|
39 | try { |
---|
40 | unwind_other(total_frames); |
---|
41 | } catch (EmptyException &) { |
---|
42 | asm volatile ("# catch block (base)"); |
---|
43 | } |
---|
44 | } |
---|
45 | time_point<steady_clock> end_time = steady_clock::now(); |
---|
46 | nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time); |
---|
47 | cout << "Run-Time (s): " << fixed << setprecision(1) << duration.count() / 1'000'000'000. << endl; |
---|
48 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.