ADT
ast-experimental
enum
forall-pointer-decay
jacob/cs343-translation
new-ast-unique-expr
pthread-emulation
qualifiedEnum
Last change
on this file since d83b266 was 11d4fa5, checked in by Andrew Beach <ajbeach@…>, 4 years ago |
Updated the Java exception benchmarks to provide some warm-up. Does not appear to change results.
|
-
Property mode
set to
100644
|
File size:
990 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 | static void throw_exception() throws EmptyException {
|
---|
9 | throw new EmptyException();
|
---|
10 | }
|
---|
11 |
|
---|
12 | static void cond_catch() throws EmptyException {
|
---|
13 | try {
|
---|
14 | throw_exception();
|
---|
15 | } catch (EmptyException exc) {
|
---|
16 | if (!should_catch) {
|
---|
17 | throw exc;
|
---|
18 | }
|
---|
19 | }
|
---|
20 | }
|
---|
21 |
|
---|
22 | private static long loop(int times) {
|
---|
23 | long startTime = System.nanoTime();
|
---|
24 | for (int count = 0 ; count < times ; ++count) {
|
---|
25 | try {
|
---|
26 | cond_catch();
|
---|
27 | } catch (EmptyException exc) {
|
---|
28 | // ...
|
---|
29 | }
|
---|
30 | }
|
---|
31 | long endTime = System.nanoTime();
|
---|
32 | return endTime - startTime;
|
---|
33 | }
|
---|
34 |
|
---|
35 | public static void main(String[] args) {
|
---|
36 | int times = 1;
|
---|
37 | if (0 < args.length) {
|
---|
38 | times = Integer.parseInt(args[0]);
|
---|
39 | }
|
---|
40 | if (1 < args.length) {
|
---|
41 | should_catch = 0 != Integer.parseInt(args[1]);
|
---|
42 | }
|
---|
43 |
|
---|
44 | // Warm-Up:
|
---|
45 | loop(1000);
|
---|
46 |
|
---|
47 | long time = loop(times);
|
---|
48 | System.out.println("Run-Time (ns): " + time);
|
---|
49 | }
|
---|
50 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.