ADT
        ast-experimental
        enum
        forall-pointer-decay
        jacob/cs343-translation
        pthread-emulation
        qualifiedEnum
      
      
        
          | Last change
 on this file since a916aad was             f79ee0d, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago | 
        
          | 
update exception benchmarks
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            1.1 KB | 
      
      
| Rev | Line |  | 
|---|
| [f79ee0d] | 1 | // Resume Across Fixup | 
|---|
|  | 2 | #include <chrono> | 
|---|
|  | 3 | #include <cstdlib> | 
|---|
|  | 4 | #include <exception> | 
|---|
|  | 5 | #include <iostream> | 
|---|
|  | 6 | #include <iomanip> | 
|---|
|  | 7 | #include <functional> | 
|---|
|  | 8 |  | 
|---|
|  | 9 | using namespace std; | 
|---|
|  | 10 | using namespace chrono; | 
|---|
|  | 11 |  | 
|---|
|  | 12 | void nounwind_fixup(unsigned int frames, function<void (int &)> raised_rtn ) { | 
|---|
|  | 13 | if (frames) { | 
|---|
|  | 14 | nounwind_fixup(frames - 1, raised_rtn); | 
|---|
|  | 15 | } else { | 
|---|
|  | 16 | int fixup = 17; | 
|---|
|  | 17 | raised_rtn(fixup); | 
|---|
|  | 18 | } | 
|---|
|  | 19 | } | 
|---|
|  | 20 |  | 
|---|
|  | 21 | int main(int argc, char * argv[]) { | 
|---|
|  | 22 | unsigned int times = 1; | 
|---|
|  | 23 | unsigned int total_frames = 1; | 
|---|
|  | 24 | if (1 < argc) { | 
|---|
|  | 25 | times = strtol(argv[1], nullptr, 10); | 
|---|
|  | 26 | } | 
|---|
|  | 27 | if (2 < argc) { | 
|---|
|  | 28 | total_frames = strtol(argv[2], nullptr, 10); | 
|---|
|  | 29 | } | 
|---|
|  | 30 |  | 
|---|
|  | 31 | auto raised = [=] (int & fixup) -> void { | 
|---|
|  | 32 | fixup = total_frames + 42;            // use local scope => lexical link | 
|---|
|  | 33 | }; | 
|---|
|  | 34 | time_point<steady_clock> start_time = steady_clock::now(); | 
|---|
|  | 35 | for (unsigned int count = 0 ; count < times ; ++count) { | 
|---|
|  | 36 | nounwind_fixup(total_frames, raised); | 
|---|
|  | 37 | } | 
|---|
|  | 38 | time_point<steady_clock> end_time = steady_clock::now(); | 
|---|
|  | 39 | nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time); | 
|---|
|  | 40 | cout << "Run-Time (s): " << fixed << setprecision(1) << duration.count() / 1'000'000'000. << endl; | 
|---|
|  | 41 | } | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.