ADTast-experimental
Last change
on this file since 9feb34b was
812ba3d,
checked in by Andrew Beach <ajbeach@…>, 3 years ago
|
Some clean-up to make Peter's changes to the exception benchmarks fit in better. And make test.sh a bit more robust.
|
-
Property mode set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[f79ee0d] | 1 | // Resume Across Other Handler |
---|
| 2 | #include <clock.hfa> |
---|
| 3 | #include <exception.hfa> |
---|
| 4 | #include <fstream.hfa> |
---|
[812ba3d] | 5 | #include <stdlib.hfa> |
---|
[f79ee0d] | 6 | |
---|
| 7 | exception fixup_exception { |
---|
| 8 | int & fixup; |
---|
| 9 | }; |
---|
| 10 | vtable(fixup_exception) fixup_vt; |
---|
| 11 | exception not_raised_exception { |
---|
| 12 | int & fixup; |
---|
| 13 | }; |
---|
| 14 | |
---|
[812ba3d] | 15 | // Using a global value to allow hoisting (and avoid thunks). |
---|
| 16 | unsigned int frames; |
---|
[f79ee0d] | 17 | |
---|
| 18 | void nounwind_other(unsigned int dummy) { |
---|
| 19 | if (frames) { |
---|
| 20 | frames -= 1; |
---|
| 21 | try { |
---|
| 22 | nounwind_other(42); |
---|
[812ba3d] | 23 | // Always false, but prevents recursion elimination. |
---|
| 24 | if (-1 == frames) printf("~"); |
---|
[f79ee0d] | 25 | } catchResume (not_raised_exception * ex) { |
---|
[812ba3d] | 26 | ex->fixup = frames + 42; |
---|
[f79ee0d] | 27 | } |
---|
| 28 | } else { |
---|
| 29 | int fixup = dummy; |
---|
[812ba3d] | 30 | throwResume (fixup_exception){&fixup_vt, fixup}; |
---|
[f79ee0d] | 31 | } |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | int main(int argc, char * argv[]) { |
---|
| 35 | unsigned int times = 1; |
---|
| 36 | unsigned int total_frames = 1; |
---|
| 37 | if (1 < argc) { |
---|
| 38 | times = strto(argv[1], 0p, 10); |
---|
| 39 | } |
---|
| 40 | if (2 < argc) { |
---|
| 41 | total_frames = strto(argv[2], 0p, 10); |
---|
| 42 | } |
---|
| 43 | frames = total_frames; |
---|
| 44 | |
---|
| 45 | Time start_time = timeHiRes(); |
---|
| 46 | for (int count = 0 ; count < times ; ++count) { |
---|
| 47 | try { |
---|
| 48 | nounwind_other(42); |
---|
| 49 | } catchResume (fixup_exception * ex) { |
---|
| 50 | ex->fixup = total_frames + 42; |
---|
| 51 | } |
---|
| 52 | } |
---|
| 53 | Time end_time = timeHiRes(); |
---|
| 54 | sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.); |
---|
| 55 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.