source: doc/theses/andrew_beach_MMath/code/resume-finally.cfa @ 2a3f0d9

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationpthread-emulationqualifiedEnum
Last change on this file since 2a3f0d9 was f79ee0d, checked in by Peter A. Buhr <pabuhr@…>, 3 years ago

update exception benchmarks

  • Property mode set to 100644
File size: 931 bytes
Line 
1// Throw Across Finally
2#include <clock.hfa>
3#include <exception.hfa>
4#include <fstream.hfa>
5#include <stdlib.hfa>                                                                   // strto
6
7exception empty_exception;
8vtable(empty_exception) empty_vt;
9
10void unwind_finally(unsigned int frames) {
11        if (frames) {
12                try {
13                        unwind_finally(frames - 1);
14                } finally {
15                        asm volatile ("# finally block");
16                }
17        } else {
18                throwResume (empty_exception){&empty_vt};
19        }
20}
21
22int main(int argc, char * argv[]) {
23        unsigned int times = 1;
24        unsigned int total_frames = 1;
25        if (1 < argc) {
26                times = strto(argv[1], 0p, 10);
27        }
28        if (2 < argc) {
29                total_frames = strto(argv[2], 0p, 10);
30        }
31
32        Time start_time = timeHiRes();
33        for (int count = 0 ; count < times ; ++count) {
34                try {
35                        unwind_finally(total_frames);
36                } catchResume (empty_exception *) {
37                        asm volatile ("# fixup block");
38                }
39        }
40        Time end_time = timeHiRes();
41        sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
42}
Note: See TracBrowser for help on using the repository browser.