ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since 98233b3 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:
791 bytes
|
Rev | Line | |
---|
[63e3ed8] | 1 | #!/usr/bin/env python3 |
---|
| 2 | |
---|
| 3 | # Conditional Match (or Re-Raise) |
---|
| 4 | |
---|
| 5 | from time import thread_time_ns |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | class EmptyException(Exception): |
---|
| 9 | pass |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | should_catch = False |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | def throw_exception(): |
---|
| 16 | raise EmptyException() |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | def cond_catch(): |
---|
| 20 | try: |
---|
| 21 | throw_exception() |
---|
| 22 | except EmptyException as exc: |
---|
| 23 | if not should_catch: |
---|
| 24 | raise |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | def 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 | |
---|
| 45 | if '__main__' == __name__: |
---|
| 46 | import sys |
---|
| 47 | main(sys.argv) |
---|
Note: See
TracBrowser
for help on using the repository browser.