ADTast-experimentalpthread-emulation
Last change
on this file since ce1d721 was
f79ee0d,
checked in by Peter A. Buhr <pabuhr@…>, 3 years ago
|
update exception benchmarks
|
-
Property mode set to
100644
|
File size:
764 bytes
|
Rev | Line | |
---|
[ea593a3] | 1 | // Enter and Leave a Try Statement with a Termination Handler |
---|
| 2 | |
---|
| 3 | class NotRaisedException extends Exception {} |
---|
| 4 | |
---|
[f79ee0d] | 5 | public class TryCatch { |
---|
[11d4fa5] | 6 | private static boolean shouldThrow = false; |
---|
[ea593a3] | 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 { |
---|
| 12 | if (shouldThrow) { |
---|
| 13 | throw new NotRaisedException(); |
---|
| 14 | } |
---|
| 15 | } catch (NotRaisedException e) { |
---|
| 16 | // ... |
---|
| 17 | } |
---|
| 18 | } |
---|
[ee23a8d] | 19 | long endTime = System.nanoTime(); |
---|
[11d4fa5] | 20 | return endTime - startTime; |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | public static void main(String[] args) { |
---|
| 24 | int times = 1; |
---|
| 25 | if (0 < args.length) { |
---|
| 26 | times = Integer.parseInt(args[0]); |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | // Warm-Up: |
---|
| 30 | loop(1000); |
---|
| 31 | |
---|
| 32 | long time = loop(times); |
---|
[f79ee0d] | 33 | System.out.format("Run-Time (s): %.1f%n", time / 1_000_000_000.); |
---|
[ea593a3] | 34 | } |
---|
| 35 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.