Last change
on this file since 4c2e561 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.4 KB
|
Rev | Line | |
---|
[f79ee0d] | 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, function<void (int &)> not_raised_rtn ) {
|
---|
| 13 | auto not_raised = [=](int & fixup) -> void {
|
---|
| 14 | fixup = frames + 42; // use local scope => lexical link
|
---|
| 15 | };
|
---|
| 16 |
|
---|
| 17 | if (frames) {
|
---|
| 18 | nounwind_fixup(frames - 1, raised_rtn, not_raised);
|
---|
| 19 | } else {
|
---|
| 20 | int fixup = 17;
|
---|
| 21 | raised_rtn(fixup);
|
---|
| 22 | }
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | int main(int argc, char * argv[]) {
|
---|
| 26 | unsigned int times = 1;
|
---|
| 27 | unsigned int total_frames = 1;
|
---|
| 28 | if (1 < argc) {
|
---|
| 29 | times = strtol(argv[1], nullptr, 10);
|
---|
| 30 | }
|
---|
| 31 | if (2 < argc) {
|
---|
| 32 | total_frames = strtol(argv[2], nullptr, 10);
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | auto raised = [=] (int & fixup) -> void {
|
---|
| 36 | fixup = total_frames + 42; // use local scope => lexical link
|
---|
| 37 | };
|
---|
| 38 | auto not_raised = [=] (int & fixup) -> void {
|
---|
| 39 | fixup = total_frames + 42; // use local scope => lexical link
|
---|
| 40 | };
|
---|
| 41 |
|
---|
| 42 | time_point<steady_clock> start_time = steady_clock::now();
|
---|
| 43 | for (unsigned int count = 0 ; count < times ; ++count) {
|
---|
| 44 | nounwind_fixup(total_frames, raised, not_raised);
|
---|
| 45 | }
|
---|
| 46 | time_point<steady_clock> end_time = steady_clock::now();
|
---|
| 47 | nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time);
|
---|
| 48 | cout << "Run-Time (s): " << fixed << setprecision(1) << duration.count() / 1'000'000'000. << endl;
|
---|
| 49 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.