source: doc/theses/andrew_beach_MMath/code/fixup-empty-r.cfa@ 82e5670

Last change on this file since 82e5670 was 812ba3d, checked in by Andrew Beach <ajbeach@…>, 4 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: 1002 bytes
RevLine 
[f79ee0d]1// Resume Across Empty Function
2#include <clock.hfa>
3#include <exception.hfa>
4#include <fstream.hfa>
[812ba3d]5#include <stdlib.hfa>
[f79ee0d]6
7exception fixup_exception {
8 int & fixup;
9};
10vtable(fixup_exception) fixup_vt;
11
[18783b4]12void nounwind_empty(unsigned int frames) {
[f79ee0d]13 if (frames) {
[18783b4]14 nounwind_empty(frames - 1);
[812ba3d]15 // "Always" false, but prevents recursion elimination.
16 if (-1 == frames) printf("~");
[f79ee0d]17 } else {
18 int fixup = 17;
[812ba3d]19 throwResume (fixup_exception){&fixup_vt, fixup};
[f79ee0d]20 }
21}
22
23int main(int argc, char * argv[]) {
24 unsigned int times = 1;
25 unsigned int total_frames = 1;
26 if (1 < argc) {
27 times = strto(argv[1], 0p, 10);
28 }
29 if (2 < argc) {
30 total_frames = strto(argv[2], 0p, 10);
31 }
32
33 Time start_time = timeHiRes();
34 for (unsigned int count = 0 ; count < times ; ++count) {
35 try {
36 nounwind_empty(total_frames);
37 } catchResume (fixup_exception * ex) {
38 ex->fixup = total_frames + 42;
39 }
40 }
41 Time end_time = timeHiRes();
42 sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
43}
Note: See TracBrowser for help on using the repository browser.