source: doc/theses/andrew_beach_MMath/code/throw-other.cfa @ 594e1db

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

update exception benchmarks

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