source:
doc/theses/andrew_beach_MMath/code/throw-empty.cfa
@
ce1d721
Last change on this file since ce1d721 was 347925c, checked in by , 3 years ago | |
---|---|
|
|
File size: 966 bytes |
Rev | Line | |
---|---|---|
[ea593a3] | 1 | // Throw Across Empty Function |
[ee23a8d] | 2 | #include <clock.hfa> |
[ea593a3] | 3 | #include <exception.hfa> |
[ee23a8d] | 4 | #include <fstream.hfa> |
[f79ee0d] | 5 | #include <stdlib.hfa> // strto |
[ea593a3] | 6 | |
[f79ee0d] | 7 | exception empty_exception; |
8 | vtable(empty_exception) empty_vt; | |
[ea593a3] | 9 | |
10 | void unwind_empty(unsigned int frames) { | |
11 | if (frames) { | |
12 | unwind_empty(frames - 1); | |
[347925c] | 13 | if ( frames == -1 ) printf( "42" ); // prevent recursion optimizations |
[ea593a3] | 14 | } else { |
15 | throw (empty_exception){&empty_vt}; | |
16 | } | |
17 | } | |
18 | ||
19 | int main(int argc, char * argv[]) { | |
20 | unsigned int times = 1; | |
21 | unsigned int total_frames = 1; | |
[ee23a8d] | 22 | if (1 < argc) { |
[f79ee0d] | 23 | times = strto(argv[1], 0p, 10); |
[ea593a3] | 24 | } |
[ee23a8d] | 25 | if (2 < argc) { |
[f79ee0d] | 26 | total_frames = strto(argv[2], 0p, 10); |
[ea593a3] | 27 | } |
28 | ||
[ee23a8d] | 29 | Time start_time = timeHiRes(); |
[ea593a3] | 30 | for (unsigned int count = 0 ; count < times ; ++count) { |
31 | try { | |
32 | unwind_empty(total_frames); | |
33 | } catch (empty_exception *) { | |
[54651005] | 34 | asm volatile ("# catch block"); |
[ea593a3] | 35 | } |
36 | } | |
[ee23a8d] | 37 | Time end_time = timeHiRes(); |
[f79ee0d] | 38 | sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.); |
[ea593a3] | 39 | } |
Note: See TracBrowser
for help on using the repository browser.