source: doc/theses/andrew_beach_MMath/code/throw-empty.cpp @ b183717

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationpthread-emulationqualifiedEnum
Last change on this file since b183717 was f79ee0d, checked in by Peter A. Buhr <pabuhr@…>, 3 years ago

update exception benchmarks

  • Property mode set to 100644
File size: 1.0 KB
Line 
1// Throw Across Empty Function
2#include <chrono>
3#include <cstdlib>
4#include <exception>
5#include <iostream>
6#include <iomanip>
7
8using namespace std;
9using namespace std::chrono;
10
11struct EmptyException : public std::exception {};
12
13void unwind_empty(unsigned int frames) {
14        if (frames) {
15                unwind_empty(frames - 1);
16        } else {
17                throw (EmptyException){};
18        }
19}
20
21int main(int argc, char * argv[]) {
22        unsigned int times = 1;
23        unsigned int total_frames = 1;
24        if (1 < argc) {
25                times = strtol(argv[1], nullptr, 10);
26        }
27        if (2 < argc) {
28                total_frames = strtol(argv[2], nullptr, 10);
29        }
30
31        time_point<steady_clock> start_time = steady_clock::now();
32        for (unsigned int count = 0 ; count < times ; ++count) {
33                try {
34                        unwind_empty(total_frames);
35                } catch (EmptyException &) {
36                        asm volatile ("# catch block");
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.