ADT
        ast-experimental
        enum
        forall-pointer-decay
        jacob/cs343-translation
        new-ast-unique-expr
        pthread-emulation
        qualifiedEnum
      
      
        
          | 
            Last change
 on this file since a5a6a1a8 was             54651005, checked in by Andrew Beach <ajbeach@…>, 4 years ago           | 
        
        
          | 
             
Added asm statements to the exception benchmarks to prevent unwanted optimizations. 
 
           | 
        
        
          
            
              - 
Property                 mode
 set to                 
100644
               
             
           | 
        
        
          | 
            File size:
            974 bytes
           | 
        
      
      
| Rev | Line |   | 
|---|
| [ea593a3] | 1 | // Throw Across Destructor
 | 
|---|
| [ee23a8d] | 2 | #include <clock.hfa>
 | 
|---|
| [ea593a3] | 3 | #include <exception.hfa>
 | 
|---|
| [ee23a8d] | 4 | #include <fstream.hfa>
 | 
|---|
| [ea593a3] | 5 | #include <stdlib.hfa>
 | 
|---|
 | 6 | 
 | 
|---|
 | 7 | EHM_EXCEPTION(empty_exception)();
 | 
|---|
 | 8 | 
 | 
|---|
 | 9 | EHM_VIRTUAL_TABLE(empty_exception, empty_vt);
 | 
|---|
 | 10 | 
 | 
|---|
 | 11 | struct WithDestructor {};
 | 
|---|
 | 12 | 
 | 
|---|
 | 13 | void ^?{}(WithDestructor & this) {
 | 
|---|
| [54651005] | 14 |         asm volatile ("# destructor body");
 | 
|---|
| [ea593a3] | 15 | }
 | 
|---|
 | 16 | 
 | 
|---|
 | 17 | void unwind_destructor(unsigned int frames) {
 | 
|---|
 | 18 |         if (frames) {
 | 
|---|
 | 19 |                 WithDestructor object;
 | 
|---|
 | 20 |                 unwind_destructor(frames - 1);
 | 
|---|
 | 21 |         } else {
 | 
|---|
 | 22 |                 throw (empty_exception){&empty_vt};
 | 
|---|
 | 23 |         }
 | 
|---|
 | 24 | }
 | 
|---|
 | 25 | 
 | 
|---|
 | 26 | int main(int argc, char * argv[]) {
 | 
|---|
 | 27 |         unsigned int times = 1;
 | 
|---|
 | 28 |         unsigned int total_frames = 1;
 | 
|---|
| [ee23a8d] | 29 |         if (1 < argc) {
 | 
|---|
| [ea593a3] | 30 |                 times = strtol(argv[1], 0p, 10);
 | 
|---|
 | 31 |         }
 | 
|---|
| [ee23a8d] | 32 |         if (2 < argc) {
 | 
|---|
| [ea593a3] | 33 |                 total_frames = strtol(argv[2], 0p, 10);
 | 
|---|
 | 34 |         }
 | 
|---|
 | 35 | 
 | 
|---|
| [ee23a8d] | 36 |         Time start_time = timeHiRes();
 | 
|---|
| [ea593a3] | 37 |         for (int count = 0 ; count < times ; ++count) {
 | 
|---|
 | 38 |                 try {
 | 
|---|
 | 39 |                         unwind_destructor(total_frames);
 | 
|---|
 | 40 |                 } catch (empty_exception *) {
 | 
|---|
| [54651005] | 41 |                         asm volatile ("# catch block");
 | 
|---|
| [ea593a3] | 42 |                 }
 | 
|---|
 | 43 |         }
 | 
|---|
| [ee23a8d] | 44 |         Time end_time = timeHiRes();
 | 
|---|
 | 45 |         sout | "Run-Time (ns): " | (end_time - start_time)`ns;
 | 
|---|
| [ea593a3] | 46 | }
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.