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