source: doc/theses/andrew_beach_MMath/code/cond-fixup.cfa @ ba0d2ea

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since ba0d2ea 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: 948 bytes
RevLine 
[ea593a3]1// Conditional Match (or Re-Raise)
[ee23a8d]2#include <clock.hfa>
[ea593a3]3#include <exception.hfa>
[ee23a8d]4#include <fstream.hfa>
[ea593a3]5#include <stdlib.hfa>
6
7EHM_EXCEPTION(empty_exception)();
8
9EHM_VIRTUAL_TABLE(empty_exception, empty_vt);
10
11bool should_catch = false;
12
13void throw_exception() {
[d2278e9]14        throwResume (empty_exception){&empty_vt};
[ea593a3]15}
16
17void cond_catch() {
18        try {
19                throw_exception();
[d2278e9]20        } catchResume (empty_exception * exc ; should_catch) {
[54651005]21                asm volatile ("# fixup block (conditional)");
[ea593a3]22        }
23}
24
25int main(int argc, char * argv[]) {
26        unsigned int times = 1;
[ee23a8d]27        if (1 < argc) {
[ea593a3]28                times = strtol(argv[1], 0p, 10);
29        }
[ee23a8d]30        if (2 < argc) {
[11ad42f]31                should_catch = strtol(argv[2], 0p, 10);
[ea593a3]32        }
33
[47e413b]34        Time start_time = timeHiRes();
[ea593a3]35        for (unsigned int count = 0 ; count < times ; ++count) {
36                try {
37                        cond_catch();
[d2278e9]38                } catchResume (empty_exception * exc) {
[54651005]39                        asm volatile ("# fixup block (unconditional)");
[ea593a3]40                }
41        }
[47e413b]42        Time end_time = timeHiRes();
[ee23a8d]43        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
[ea593a3]44}
Note: See TracBrowser for help on using the repository browser.