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