source: doc/theses/andrew_beach_MMath/code/throw-finally.cfa @ ced5e2a

ADTast-experimentalpthread-emulationqualifiedEnum
Last change on this file since ced5e2a was f79ee0d, checked in by Peter A. Buhr <pabuhr@…>, 3 years ago

update exception benchmarks

  • Property mode set to 100644
File size: 1.0 KB
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
10unsigned int frames;                                                                    // use global because of gcc thunk problem
11
12void unwind_finally(unsigned int dummy) {
13        if (frames) {
14                frames -= 1;
15                try {
16                        unwind_finally(42);
17                } finally {
18                        asm volatile ("# finally block");
19                }
20        } else {
21                dummy = 42;
22                throw (empty_exception){&empty_vt};
23        }
24}
25
26int main(int argc, char * argv[]) {
27        unsigned int times = 1;
28        unsigned int total_frames = 1;
29        if (1 < argc) {
30                times = strto(argv[1], 0p, 10);
31        }
32        if (2 < argc) {
33                total_frames = strto(argv[2], 0p, 10);
34        }
35        frames = total_frames;
36
37        Time start_time = timeHiRes();
38        for (int count = 0 ; count < times ; ++count) {
39                try {
40                        unwind_finally(42);
41                } catch (empty_exception *) {
42                        asm volatile ("# catch block");
43                }
44        }
45        Time end_time = timeHiRes();
46        sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
47}
Note: See TracBrowser for help on using the repository browser.