source: doc/theses/andrew_beach_MMath/code/cross-finally.cfa @ a5a6a1a8

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since a5a6a1a8 was 54651005, checked in by Andrew Beach <ajbeach@…>, 3 years ago

Added asm statements to the exception benchmarks to prevent unwanted optimizations.

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