ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since 815c6ae was
e19fadd,
checked in by Andrew Beach <ajbeach@…>, 3 years ago
|
Fixed an error in exception benchmarks. C++ conditional catch was reversed.
|
-
Property mode set to
100644
|
File size:
994 bytes
|
Line | |
---|
1 | // Conditional Match (or Re-Raise) |
---|
2 | #include <chrono> |
---|
3 | #include <cstdlib> |
---|
4 | #include <exception> |
---|
5 | #include <iostream> |
---|
6 | |
---|
7 | using namespace std::chrono; |
---|
8 | |
---|
9 | struct EmptyException : public std::exception {}; |
---|
10 | |
---|
11 | bool should_catch = false; |
---|
12 | |
---|
13 | void throw_exception() { |
---|
14 | throw EmptyException(); |
---|
15 | } |
---|
16 | |
---|
17 | void cond_catch() { |
---|
18 | try { |
---|
19 | throw_exception(); |
---|
20 | } catch (EmptyException & exc) { |
---|
21 | if (!should_catch) { |
---|
22 | throw; |
---|
23 | } |
---|
24 | } |
---|
25 | } |
---|
26 | |
---|
27 | int main(int argc, char * argv[]) { |
---|
28 | unsigned int times = 1; |
---|
29 | if (1 < argc) { |
---|
30 | times = strtol(argv[1], nullptr, 10); |
---|
31 | } |
---|
32 | if (2 < argc) { |
---|
33 | should_catch = strtol(argv[2], nullptr, 10); |
---|
34 | } |
---|
35 | |
---|
36 | time_point<steady_clock> start_time = steady_clock::now(); |
---|
37 | for (unsigned int count = 0 ; count < times ; ++count) { |
---|
38 | try { |
---|
39 | cond_catch(); |
---|
40 | } catch (EmptyException &) { |
---|
41 | // ... |
---|
42 | } |
---|
43 | } |
---|
44 | time_point<steady_clock> end_time = steady_clock::now(); |
---|
45 | nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time); |
---|
46 | std::cout << "Run-Time (ns): " << duration.count() << std::endl; |
---|
47 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.