source: doc/theses/andrew_beach_MMath/code/fixup-empty-f.cfa @ 2514d3d7

Last change on this file since 2514d3d7 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: 981 bytes
Line 
1// Resume Across Fixup
2#include <clock.hfa>
3#include <fstream.hfa>
4#include <stdlib.hfa>
5
6void nounwind_fixup(unsigned int frames, void (*raised_rtn)(int &)) {
7        if (frames) {
8                nounwind_fixup(frames - 1, raised_rtn);
9                // "Always" false, but prevents recursion elimination.
10                if (-1 == frames) printf("~");
11        } else {
12                int fixup = 17;
13                raised_rtn(fixup);
14        }
15}
16
17int main(int argc, char * argv[]) {
18        unsigned int times = 1;
19        unsigned int total_frames = 1;
20        if (1 < argc) {
21                times = strto(argv[1], 0p, 10);
22        }
23        if (2 < argc) {
24                total_frames = strto(argv[2], 0p, 10);
25        }
26
27        // Closures at the top level are allowed to be true closures.
28        void raised(int & fixup) {
29                fixup = total_frames + 42;
30                if (total_frames == 42) printf("42");
31        }
32
33        Time start_time = timeHiRes();
34        for (unsigned int count = 0 ; count < times ; ++count) {
35                nounwind_fixup(total_frames, raised);
36        }
37        Time end_time = timeHiRes();
38        sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
39}
Note: See TracBrowser for help on using the repository browser.