ADT
ast-experimental
enum
forall-pointer-decay
jacob/cs343-translation
new-ast-unique-expr
pthread-emulation
qualifiedEnum
|
Last change
on this file since 93bbbc4 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:
946 bytes
|
| Line | |
|---|
| 1 | // Throw Across Empty Function
|
|---|
| 2 | #include <chrono>
|
|---|
| 3 | #include <cstdlib>
|
|---|
| 4 | #include <exception>
|
|---|
| 5 | #include <iostream>
|
|---|
| 6 |
|
|---|
| 7 | using namespace std::chrono;
|
|---|
| 8 |
|
|---|
| 9 | struct EmptyException : public std::exception {};
|
|---|
| 10 |
|
|---|
| 11 | void unwind_empty(unsigned int frames) {
|
|---|
| 12 | if (frames) {
|
|---|
| 13 | unwind_empty(frames - 1);
|
|---|
| 14 | } else {
|
|---|
| 15 | throw (EmptyException){};
|
|---|
| 16 | }
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | int main(int argc, char * argv[]) {
|
|---|
| 20 | unsigned int times = 1;
|
|---|
| 21 | unsigned int total_frames = 1;
|
|---|
| 22 | if (1 < argc) {
|
|---|
| 23 | times = strtol(argv[1], nullptr, 10);
|
|---|
| 24 | }
|
|---|
| 25 | if (2 < argc) {
|
|---|
| 26 | total_frames = strtol(argv[2], nullptr, 10);
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | time_point<steady_clock> start_time = steady_clock::now();
|
|---|
| 30 | for (unsigned int count = 0 ; count < times ; ++count) {
|
|---|
| 31 | try {
|
|---|
| 32 | unwind_empty(total_frames);
|
|---|
| 33 | } catch (EmptyException &) {
|
|---|
| 34 | // ...
|
|---|
| 35 | }
|
|---|
| 36 | }
|
|---|
| 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;
|
|---|
| 40 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.