source: doc/theses/andrew_beach_MMath/code/throw-detor.cpp@ 37c6f77

ADT ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 37c6f77 was ee23a8d, checked in by Andrew Beach <ajbeach@…>, 4 years ago

Added duration information (in nanoseconds) to EHM benchmarks.

  • Property mode set to 100644
File size: 1023 bytes
RevLine 
[ea593a3]1// Throw Across Destructor
[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
11struct WithDestructor {
12 ~WithDestructor() {}
13};
14
15void unwind_destructor(unsigned int frames) {
16 if (frames) {
17 WithDestructor object;
18 unwind_destructor(frames - 1);
19 } else {
20 throw (EmptyException){};
21 }
22}
23
24int main(int argc, char * argv[]) {
25 unsigned int times = 1;
26 unsigned int total_frames = 1;
[ee23a8d]27 if (1 < argc) {
[ea593a3]28 times = strtol(argv[1], nullptr, 10);
29 }
[ee23a8d]30 if (2 < argc) {
[ea593a3]31 total_frames = strtol(argv[2], nullptr, 10);
32 }
33
[ee23a8d]34 time_point<steady_clock> start_time = steady_clock::now();
[ea593a3]35 for (int count = 0 ; count < times ; ++count) {
36 try {
37 unwind_destructor(total_frames);
38 } catch (EmptyException &) {
39 // ...
40 }
41 }
[ee23a8d]42 time_point<steady_clock> end_time = steady_clock::now();
43 nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time);
44 std::cout << "Run-Time (ns): " << duration.count() << std::endl;
[ea593a3]45}
Note: See TracBrowser for help on using the repository browser.