ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationpthread-emulationqualifiedEnum
Last change
on this file since 678f259 was
678f259,
checked in by Andrew Beach <ajbeach@…>, 3 years ago
|
Some clean-up in the exception benchmark directory. Mostly just shortening names.
|
-
Property mode set to
100644
|
File size:
994 bytes
|
Line | |
---|
1 | // Resume Across Fixup |
---|
2 | #include <clock.hfa> |
---|
3 | #include <fstream.hfa> |
---|
4 | #include <stdlib.hfa> // strto |
---|
5 | |
---|
6 | int nounwind_fixup(unsigned int frames, void (*raised_rtn)(int &)) { |
---|
7 | if (frames) { |
---|
8 | int rtn = nounwind_fixup(frames - 1, raised_rtn); |
---|
9 | if ( rtn == 42 ) printf( "42" ); // make non-tail recursive |
---|
10 | return rtn; |
---|
11 | |
---|
12 | } else { |
---|
13 | int fixup = 17; |
---|
14 | raised_rtn(fixup); |
---|
15 | return fixup; |
---|
16 | } |
---|
17 | } |
---|
18 | |
---|
19 | int main(int argc, char * argv[]) { |
---|
20 | unsigned int times = 1; |
---|
21 | unsigned int total_frames = 1; |
---|
22 | if (1 < argc) { |
---|
23 | times = strto(argv[1], 0p, 10); |
---|
24 | } |
---|
25 | if (2 < argc) { |
---|
26 | total_frames = strto(argv[2], 0p, 10); |
---|
27 | } |
---|
28 | |
---|
29 | void raised(int & fixup) { |
---|
30 | fixup = total_frames + 42; // use local scope => lexical link |
---|
31 | if ( total_frames == 42 ) printf( "42" ); |
---|
32 | } |
---|
33 | |
---|
34 | Time start_time = timeHiRes(); |
---|
35 | for (unsigned int count = 0 ; count < times ; ++count) { |
---|
36 | nounwind_fixup(total_frames, raised); |
---|
37 | } |
---|
38 | Time end_time = timeHiRes(); |
---|
39 | sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.); |
---|
40 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.