Last change
on this file since aa14aafe was
f79ee0d,
checked in by Peter A. Buhr <pabuhr@…>, 3 years ago
|
update exception benchmarks
|
-
Property mode set to
100644
|
File size:
872 bytes
|
Line | |
---|
1 | // Conditional Match (or Re-Raise) |
---|
2 | |
---|
3 | class EmptyException extends Exception {} |
---|
4 | |
---|
5 | public class CondCatch { |
---|
6 | static boolean should_catch = 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 | try { |
---|
13 | throw new EmptyException(); |
---|
14 | } catch (EmptyException exc) { |
---|
15 | if (!should_catch) { |
---|
16 | throw exc; |
---|
17 | } |
---|
18 | } |
---|
19 | } catch (EmptyException exc) { |
---|
20 | // ... |
---|
21 | } |
---|
22 | } |
---|
23 | long endTime = System.nanoTime(); |
---|
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); |
---|
40 | System.out.format("Run-Time (s): %.1f%n", time / 1_000_000_000.); |
---|
41 | } |
---|
42 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.