source: doc/theses/andrew_beach_MMath/code/throw-empty.cpp @ 866cad3

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 866cad3 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: 971 bytes
RevLine 
[ea593a3]1// Throw Across Empty Function
[ee23a8d]2#include <chrono>
[ea593a3]3#include <cstdlib>
[ee23a8d]4#include <exception>
5#include <iostream>
6
7using namespace std::chrono;
[ea593a3]8
9struct EmptyException : public std::exception {};
10
11void unwind_empty(unsigned int frames) {
12        if (frames) {
13                unwind_empty(frames - 1);
14        } else {
15                throw (EmptyException){};
16        }
17}
18
19int main(int argc, char * argv[]) {
20        unsigned int times = 1;
21        unsigned int total_frames = 1;
[ee23a8d]22        if (1 < argc) {
[ea593a3]23                times = strtol(argv[1], nullptr, 10);
24        }
[ee23a8d]25        if (2 < argc) {
[ea593a3]26                total_frames = strtol(argv[2], nullptr, 10);
27        }
28
[ee23a8d]29        time_point<steady_clock> start_time = steady_clock::now();
[ea593a3]30        for (unsigned int count = 0 ; count < times ; ++count) {
31                try {
32                        unwind_empty(total_frames);
33                } catch (EmptyException &) {
[54651005]34                        asm volatile ("# catch block");
[ea593a3]35                }
36        }
[ee23a8d]37        time_point<steady_clock> end_time = steady_clock::now();
38        nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time);
39        std::cout << "Run-Time (ns): " << duration.count() << std::endl;
[ea593a3]40}
Note: See TracBrowser for help on using the repository browser.