source: doc/theses/andrew_beach_MMath/code/try-catch.cfa @ 433e2c3

Last change on this file since 433e2c3 was f79ee0d, checked in by Peter A. Buhr <pabuhr@…>, 3 years ago

update exception benchmarks

  • Property mode set to 100644
File size: 778 bytes
Line 
1// Cross a Try Statement with a Termination Handler
2#include <clock.hfa>
3#include <exception.hfa>
4#include <fstream.hfa>
5#include <stdlib.hfa>                                                                   // strto
6
7exception not_raised_exception;
8vtable(not_raised_exception) not_vt;
9
10int main(int argc, char * argv[]) {
11        unsigned int times = 1;
12        volatile bool should_throw = false;
13        if (1 < argc) {
14                times = strto(argv[1], 0p, 10);
15        }
16
17        Time start_time = timeHiRes();
18        for (unsigned int count = 0 ; count < times ; ++count) {
19                try {
20                        asm volatile ("# try block");
21                        if (should_throw) {
22                                throw (not_raised_exception){&not_vt};
23                        }
24                } catch (not_raised_exception *) {
25                        asm volatile ("# catch block");
26                }
27        }
28        Time end_time = timeHiRes();
29        sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
30}
Note: See TracBrowser for help on using the repository browser.