ADT
ast-experimental
enum
forall-pointer-decay
jacob/cs343-translation
pthread-emulation
qualifiedEnum
Last change
on this file since ff3be413 was f79ee0d, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago |
update exception benchmarks
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Rev | Line | |
---|
[ea593a3] | 1 | // Throw Across Empty Function
|
---|
[ee23a8d] | 2 | #include <chrono>
|
---|
[ea593a3] | 3 | #include <cstdlib>
|
---|
[ee23a8d] | 4 | #include <exception>
|
---|
| 5 | #include <iostream>
|
---|
[f79ee0d] | 6 | #include <iomanip>
|
---|
[ee23a8d] | 7 |
|
---|
[f79ee0d] | 8 | using namespace std;
|
---|
[ee23a8d] | 9 | using namespace std::chrono;
|
---|
[ea593a3] | 10 |
|
---|
| 11 | struct EmptyException : public std::exception {};
|
---|
| 12 |
|
---|
| 13 | void unwind_empty(unsigned int frames) {
|
---|
| 14 | if (frames) {
|
---|
| 15 | unwind_empty(frames - 1);
|
---|
| 16 | } else {
|
---|
| 17 | throw (EmptyException){};
|
---|
| 18 | }
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | int main(int argc, char * argv[]) {
|
---|
| 22 | unsigned int times = 1;
|
---|
| 23 | unsigned int total_frames = 1;
|
---|
[ee23a8d] | 24 | if (1 < argc) {
|
---|
[ea593a3] | 25 | times = strtol(argv[1], nullptr, 10);
|
---|
| 26 | }
|
---|
[ee23a8d] | 27 | if (2 < argc) {
|
---|
[ea593a3] | 28 | total_frames = strtol(argv[2], nullptr, 10);
|
---|
| 29 | }
|
---|
| 30 |
|
---|
[ee23a8d] | 31 | time_point<steady_clock> start_time = steady_clock::now();
|
---|
[ea593a3] | 32 | for (unsigned int count = 0 ; count < times ; ++count) {
|
---|
| 33 | try {
|
---|
| 34 | unwind_empty(total_frames);
|
---|
| 35 | } catch (EmptyException &) {
|
---|
[54651005] | 36 | asm volatile ("# catch block");
|
---|
[ea593a3] | 37 | }
|
---|
| 38 | }
|
---|
[ee23a8d] | 39 | time_point<steady_clock> end_time = steady_clock::now();
|
---|
| 40 | nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time);
|
---|
[f79ee0d] | 41 | cout << "Run-Time (s): " << fixed << setprecision(1) << duration.count() / 1'000'000'000. << endl;
|
---|
[ea593a3] | 42 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.