ADT
        ast-experimental
        enum
        pthread-emulation
        qualifiedEnum
      
      
        
          | 
            Last change
 on this file since a38bbbc was             f79ee0d, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago           | 
        
        
          | 
             
update exception benchmarks 
 
           | 
        
        
          
            
              - 
Property                 mode
 set to                 
100644
               
             
           | 
        
        
          | 
            File size:
            764 bytes
           | 
        
      
      
| Line |   | 
|---|
| 1 | // Enter and Leave a Try Statement with a Termination Handler
 | 
|---|
| 2 | 
 | 
|---|
| 3 | class NotRaisedException extends Exception {}
 | 
|---|
| 4 | 
 | 
|---|
| 5 | public class TryCatch {
 | 
|---|
| 6 |         private static boolean shouldThrow = false;
 | 
|---|
| 7 | 
 | 
|---|
| 8 |         private static long loop(int times) {
 | 
|---|
| 9 |                 long startTime = System.nanoTime();
 | 
|---|
| 10 |                 for (int count = 0 ; count < times ; ++count) {
 | 
|---|
| 11 |                         try {
 | 
|---|
| 12 |                                 if (shouldThrow) {
 | 
|---|
| 13 |                                         throw new NotRaisedException();
 | 
|---|
| 14 |                                 }
 | 
|---|
| 15 |                         } catch (NotRaisedException e) {
 | 
|---|
| 16 |                                 // ...
 | 
|---|
| 17 |                         }
 | 
|---|
| 18 |                 }
 | 
|---|
| 19 |                 long endTime = System.nanoTime();
 | 
|---|
| 20 |                 return endTime - startTime;
 | 
|---|
| 21 |         }
 | 
|---|
| 22 | 
 | 
|---|
| 23 |         public static void main(String[] args) {
 | 
|---|
| 24 |                 int times = 1;
 | 
|---|
| 25 |                 if (0 < args.length) {
 | 
|---|
| 26 |                         times = Integer.parseInt(args[0]);
 | 
|---|
| 27 |                 }
 | 
|---|
| 28 | 
 | 
|---|
| 29 |                 // Warm-Up:
 | 
|---|
| 30 |                 loop(1000);
 | 
|---|
| 31 | 
 | 
|---|
| 32 |                 long time = loop(times);
 | 
|---|
| 33 |                 System.out.format("Run-Time (s): %.1f%n", time / 1_000_000_000.);
 | 
|---|
| 34 |         }
 | 
|---|
| 35 | }
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.