source: doc/theses/andrew_beach_MMath/code/cond_catch.py@ d83b266

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 63e3ed8, checked in by Andrew Beach <ajbeach@…>, 4 years ago

Added Python versions of the exception benchmarks.

  • Property mode set to 100755
File size: 791 bytes
Line 
1#!/usr/bin/env python3
2
3# Conditional Match (or Re-Raise)
4
5from time import thread_time_ns
6
7
8class EmptyException(Exception):
9 pass
10
11
12should_catch = False
13
14
15def throw_exception():
16 raise EmptyException()
17
18
19def cond_catch():
20 try:
21 throw_exception()
22 except EmptyException as exc:
23 if not should_catch:
24 raise
25
26
27def main(argv):
28 times = 1
29 if 1 < len(argv):
30 times = int(argv[1])
31 if 2 < len(argv):
32 should_catch = 0 < int(argv[2])
33
34 start_time = thread_time_ns()
35 for count in range(times):
36 try:
37 cond_catch();
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.