source: doc/theses/andrew_beach_MMath/code/resume-detor.cfa @ fcbb532

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

update exception benchmarks

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