| Last change
 on this file since 656c8ac was             f79ee0d, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago | 
        
          | 
update exception benchmarks
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            952 bytes | 
      
      
| Rev | Line |  | 
|---|
| [ea593a3] | 1 | // Throw Across Empty Function | 
|---|
|  | 2 |  | 
|---|
|  | 3 | class EmptyException extends Exception {} | 
|---|
|  | 4 |  | 
|---|
|  | 5 | public class ThrowEmpty { | 
|---|
|  | 6 | static void unwind_empty(int frames) throws EmptyException { | 
|---|
|  | 7 | if (0 < frames) { | 
|---|
|  | 8 | unwind_empty(frames - 1); | 
|---|
|  | 9 | } else { | 
|---|
|  | 10 | throw new EmptyException(); | 
|---|
|  | 11 | } | 
|---|
|  | 12 | } | 
|---|
|  | 13 |  | 
|---|
| [11d4fa5] | 14 | private static long loop(int times, int total_frames) { | 
|---|
|  | 15 | long startTime = System.nanoTime(); | 
|---|
|  | 16 | for (int count = 0 ; count < times ; ++count) { | 
|---|
|  | 17 | try { | 
|---|
|  | 18 | unwind_empty(total_frames); | 
|---|
|  | 19 | } catch (EmptyException e) { | 
|---|
|  | 20 | // ... | 
|---|
|  | 21 | } | 
|---|
|  | 22 | } | 
|---|
|  | 23 | long endTime = System.nanoTime(); | 
|---|
|  | 24 | return endTime - startTime; | 
|---|
|  | 25 | } | 
|---|
|  | 26 |  | 
|---|
| [ea593a3] | 27 | public static void main(String[] args) { | 
|---|
|  | 28 | int times = 1; | 
|---|
|  | 29 | int total_frames = 1; | 
|---|
|  | 30 | if (0 < args.length) { | 
|---|
|  | 31 | times = Integer.parseInt(args[0]); | 
|---|
|  | 32 | } | 
|---|
|  | 33 | if (1 < args.length) { | 
|---|
|  | 34 | total_frames = Integer.parseInt(args[1]); | 
|---|
|  | 35 | } | 
|---|
|  | 36 |  | 
|---|
| [11d4fa5] | 37 | // Warm-Up: | 
|---|
|  | 38 | loop(1000, total_frames); | 
|---|
|  | 39 |  | 
|---|
|  | 40 | long time = loop(times, total_frames); | 
|---|
| [f79ee0d] | 41 | System.out.format("Run-Time (s): %.1f%n", time / 1_000_000_000.); | 
|---|
| [ea593a3] | 42 | } | 
|---|
|  | 43 | } | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.