ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationpthread-emulationqualifiedEnum
Last change
on this file since f79ee0d 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 | // Conditional Match (or Re-Raise) |
---|
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 | bool should_catch = false; |
---|
14 | |
---|
15 | int main(int argc, char * argv[]) { |
---|
16 | unsigned int times = 1; |
---|
17 | if (1 < argc) { |
---|
18 | times = strtol(argv[1], nullptr, 10); |
---|
19 | } |
---|
20 | if (2 < argc) { |
---|
21 | should_catch = strtol(argv[2], nullptr, 10); |
---|
22 | } |
---|
23 | |
---|
24 | time_point<steady_clock> start_time = steady_clock::now(); |
---|
25 | for (unsigned int count = 0 ; count < times ; ++count) { |
---|
26 | try { |
---|
27 | try { |
---|
28 | throw EmptyException(); |
---|
29 | } catch (EmptyException & exc) { |
---|
30 | if (!should_catch) { |
---|
31 | throw; |
---|
32 | } |
---|
33 | asm volatile ("# catch block (conditional)"); |
---|
34 | } |
---|
35 | } catch (EmptyException &) { |
---|
36 | asm volatile ("# catch block (unconditional)"); |
---|
37 | } |
---|
38 | } |
---|
39 | time_point<steady_clock> end_time = steady_clock::now(); |
---|
40 | nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time); |
---|
41 | cout << "Run-Time (s): " << fixed << setprecision(1) << duration.count() / 1'000'000'000. << endl; |
---|
42 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.