source: doc/theses/andrew_beach_MMath/code/throw-detor.cfa @ 562ccf9

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

update exception benchmarks

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