source: doc/theses/andrew_beach_MMath/code/throw_other.py @ b0b89a8

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since b0b89a8 was 63e3ed8, checked in by Andrew Beach <ajbeach@…>, 3 years ago

Added Python versions of the exception benchmarks.

  • Property mode set to 100755
File size: 843 bytes
RevLine 
[63e3ed8]1#!/usr/bin/env python3
2
3# Throw Across Other Handler
4
5from time import thread_time_ns
6
7
8class EmptyException(Exception):
9    pass
10
11
12class NotRaisedException(Exception):
13    pass
14
15
16def unwind_other(frames):
17    if 0 < frames:
18        try:
19            unwind_other(frames - 1)
20        except NotRaisedException:
21            pass
22    else:
23        raise EmptyException()
24
25
26def main(argv):
27    times = 1
28    total_frames = 1
29    if 1 < len(argv):
30        times = int(argv[1])
31    if 2 < len(argv):
32        total_frames = int(argv[2])
33
34    start_time = thread_time_ns()
35    for count in range(times):
36        try:
37            unwind_other(total_frames)
38        except EmptyException:
39            pass
40
41    end_time = thread_time_ns()
42    print('Run-Time (ns):', end_time - start_time)
43
44
45if '__main__' == __name__:
46    import sys
47    main(sys.argv)
Note: See TracBrowser for help on using the repository browser.