source: doc/theses/andrew_beach_MMath/code/ThrowOther.java @ 866cad3

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 866cad3 was 11d4fa5, checked in by Andrew Beach <ajbeach@…>, 3 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: 1.2 KB
Line 
1// Throw Across Other Handler
2
3class EmptyException extends Exception {}
4
5class NotRaisedException extends Exception {}
6
7public 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 {
19                        if (should_throw) {
20                                throw new NotRaisedException();
21                        }
22                        throw new EmptyException();
23                }
24        }
25
26        private static long loop(int times, int total_frames) {
27                long startTime = System.nanoTime();
28                for (int count = 0 ; count < times ; ++count) {
29                        try {
30                                unwind_other(total_frames);
31                        } catch (EmptyException e) {
32                                // ...
33                        } catch (NotRaisedException e) {
34                                // ...
35                        }
36                }
37                long endTime = System.nanoTime();
38                return endTime - startTime;
39        }
40
41        public static void main(String[] args) {
42                int times = 1;
43                int total_frames = 1;
44                if (0 < args.length) {
45                        times = Integer.parseInt(args[0]);
46                }
47                if (1 < args.length) {
48                        total_frames = Integer.parseInt(args[1]);
49                }
50
51                // Warm-Up:
52                loop(1000, total_frames);
53
54                long time = loop(times, total_frames);
55                System.out.println("Run-Time (ns): " + time);
56        }
57}
Note: See TracBrowser for help on using the repository browser.