Last change
on this file since c2f6b79 was 678f259, checked in by Andrew Beach <ajbeach@…>, 4 years ago |
Some clean-up in the exception benchmark directory. Mostly just shortening names.
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | // Resume Across Fixup
|
---|
2 | #include <chrono>
|
---|
3 | #include <cstdlib>
|
---|
4 | #include <exception>
|
---|
5 | #include <iostream>
|
---|
6 | #include <iomanip>
|
---|
7 | #include <functional>
|
---|
8 |
|
---|
9 | using namespace std;
|
---|
10 | using namespace chrono;
|
---|
11 |
|
---|
12 | void nounwind_fixup(unsigned int frames, function<void (int &)> raised_rtn ) {
|
---|
13 | if (frames) {
|
---|
14 | nounwind_fixup(frames - 1, raised_rtn);
|
---|
15 | } else {
|
---|
16 | int fixup = 17;
|
---|
17 | raised_rtn(fixup);
|
---|
18 | }
|
---|
19 | }
|
---|
20 |
|
---|
21 | int 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 | auto raised = [=] (int & fixup) -> void {
|
---|
32 | fixup = total_frames + 42; // use local scope => lexical link
|
---|
33 | };
|
---|
34 | time_point<steady_clock> start_time = steady_clock::now();
|
---|
35 | for (unsigned int count = 0 ; count < times ; ++count) {
|
---|
36 | nounwind_fixup(total_frames, raised);
|
---|
37 | }
|
---|
38 | time_point<steady_clock> end_time = steady_clock::now();
|
---|
39 | nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time);
|
---|
40 | cout << "Run-Time (s): " << fixed << setprecision(1) << duration.count() / 1'000'000'000. << endl;
|
---|
41 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.