ADTast-experimentalenumforall-pointer-decaypthread-emulationqualifiedEnum
Last change
on this file since ab1a9ea was
f79ee0d,
checked in by Peter A. Buhr <pabuhr@…>, 3 years ago
|
update exception benchmarks
|
-
Property mode set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | // Throw Across Other Handler |
---|
2 | |
---|
3 | class EmptyException extends Exception {} |
---|
4 | |
---|
5 | class NotRaisedException extends Exception {} |
---|
6 | |
---|
7 | public class ThrowOther { |
---|
8 | static boolean should_throw = false; |
---|
9 | |
---|
10 | private static void unwind_other(int frames) |
---|
11 | throws EmptyException, NotRaisedException { |
---|
12 | if (0 < frames) { |
---|
13 | try { |
---|
14 | unwind_other(frames - 1); |
---|
15 | } catch (NotRaisedException e) { |
---|
16 | // ... |
---|
17 | } |
---|
18 | } else if (should_throw) { |
---|
19 | throw new NotRaisedException(); |
---|
20 | } else { |
---|
21 | throw new EmptyException(); |
---|
22 | } |
---|
23 | } |
---|
24 | |
---|
25 | private static long loop(int times, int total_frames) { |
---|
26 | long startTime = System.nanoTime(); |
---|
27 | for (int count = 0 ; count < times ; ++count) { |
---|
28 | try { |
---|
29 | unwind_other(total_frames); |
---|
30 | } catch (EmptyException e) { |
---|
31 | // ... |
---|
32 | } catch (NotRaisedException e) { |
---|
33 | // ... |
---|
34 | } |
---|
35 | } |
---|
36 | long endTime = System.nanoTime(); |
---|
37 | return endTime - startTime; |
---|
38 | } |
---|
39 | |
---|
40 | public static void main(String[] args) { |
---|
41 | int times = 1; |
---|
42 | int total_frames = 1; |
---|
43 | if (0 < args.length) { |
---|
44 | times = Integer.parseInt(args[0]); |
---|
45 | } |
---|
46 | if (1 < args.length) { |
---|
47 | total_frames = Integer.parseInt(args[1]); |
---|
48 | } |
---|
49 | |
---|
50 | // Warm-Up: |
---|
51 | loop(1000, total_frames); |
---|
52 | |
---|
53 | long time = loop(times, total_frames); |
---|
54 | System.out.format("Run-Time (s): %.1f%n", time / 1_000_000_000.); |
---|
55 | } |
---|
56 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.