ADT
        ast-experimental
      
      
        
          | 
            Last change
 on this file since 13f066d was             b183717, checked in by Andrew Beach <ajbeach@…>, 4 years ago           | 
        
        
          | 
             
Update another file in the exception benchmarks as well as some print formatting. 
 
           | 
        
        
          
            
              - 
Property                 mode
 set to                 
100755
               
             
           | 
        
        
          | 
            File size:
            875 bytes
           | 
        
      
      
| Line |   | 
|---|
| 1 | #!/usr/bin/env python3
 | 
|---|
| 2 | 
 | 
|---|
| 3 | # Throw Across Other Handler
 | 
|---|
| 4 | 
 | 
|---|
| 5 | from time import thread_time_ns
 | 
|---|
| 6 | 
 | 
|---|
| 7 | 
 | 
|---|
| 8 | class EmptyException(Exception):
 | 
|---|
| 9 |     pass
 | 
|---|
| 10 | 
 | 
|---|
| 11 | 
 | 
|---|
| 12 | class NotRaisedException(Exception):
 | 
|---|
| 13 |     pass
 | 
|---|
| 14 | 
 | 
|---|
| 15 | 
 | 
|---|
| 16 | def unwind_other(frames):
 | 
|---|
| 17 |     if 0 < frames:
 | 
|---|
| 18 |         try:
 | 
|---|
| 19 |             unwind_other(frames - 1)
 | 
|---|
| 20 |         except NotRaisedException:
 | 
|---|
| 21 |             pass
 | 
|---|
| 22 |     else:
 | 
|---|
| 23 |         raise EmptyException()
 | 
|---|
| 24 | 
 | 
|---|
| 25 | 
 | 
|---|
| 26 | def main(argv):
 | 
|---|
| 27 |     times = 1
 | 
|---|
| 28 |     total_frames = 1
 | 
|---|
| 29 |     if 1 < len(argv):
 | 
|---|
| 30 |         times = int(argv[1])
 | 
|---|
| 31 |     if 2 < len(argv):
 | 
|---|
| 32 |         total_frames = int(argv[2])
 | 
|---|
| 33 | 
 | 
|---|
| 34 |     start_time = thread_time_ns()
 | 
|---|
| 35 |     for count in range(times):
 | 
|---|
| 36 |         try:
 | 
|---|
| 37 |             unwind_other(total_frames)
 | 
|---|
| 38 |         except EmptyException:
 | 
|---|
| 39 |             pass
 | 
|---|
| 40 | 
 | 
|---|
| 41 |     end_time = thread_time_ns()
 | 
|---|
| 42 |     print('Run-Time (s): {:.1f}'.format((end_time - start_time) / 1_000_000_000.))
 | 
|---|
| 43 | 
 | 
|---|
| 44 | 
 | 
|---|
| 45 | if '__main__' == __name__:
 | 
|---|
| 46 |     import sys
 | 
|---|
| 47 |     main(sys.argv)
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.