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

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationpthread-emulationqualifiedEnum
Last change on this file since b183717 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
RevLine 
[ea593a3]1// Throw Across Finally
[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
[f79ee0d]10unsigned int frames;                                                                    // use global because of gcc thunk problem
[ea593a3]11
[f79ee0d]12void unwind_finally(unsigned int dummy) {
[ea593a3]13        if (frames) {
[f79ee0d]14                frames -= 1;
[ea593a3]15                try {
[f79ee0d]16                        unwind_finally(42);
[ea593a3]17                } finally {
[54651005]18                        asm volatile ("# finally block");
[ea593a3]19                }
20        } else {
[f79ee0d]21                dummy = 42;
[ea593a3]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;
[ee23a8d]29        if (1 < argc) {
[f79ee0d]30                times = strto(argv[1], 0p, 10);
[ea593a3]31        }
[ee23a8d]32        if (2 < argc) {
[f79ee0d]33                total_frames = strto(argv[2], 0p, 10);
[ea593a3]34        }
[f79ee0d]35        frames = total_frames;
[ea593a3]36
[ee23a8d]37        Time start_time = timeHiRes();
[ea593a3]38        for (int count = 0 ; count < times ; ++count) {
39                try {
[f79ee0d]40                        unwind_finally(42);
[ea593a3]41                } catch (empty_exception *) {
[54651005]42                        asm volatile ("# catch block");
[ea593a3]43                }
44        }
[ee23a8d]45        Time end_time = timeHiRes();
[f79ee0d]46        sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
[ea593a3]47}
Note: See TracBrowser for help on using the repository browser.