ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since 70df5f3 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:
777 bytes
|
Rev | Line | |
---|
[63e3ed8] | 1 | #!/usr/bin/env python3 |
---|
| 2 | |
---|
| 3 | # Throw Across Finally |
---|
| 4 | |
---|
| 5 | from time import thread_time_ns |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | class EmptyException(Exception): |
---|
| 9 | pass |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | def unwind_finally(frames): |
---|
| 13 | if 0 < frames: |
---|
| 14 | try: |
---|
| 15 | unwind_finally(frames - 1) |
---|
| 16 | finally: |
---|
| 17 | pass |
---|
| 18 | else: |
---|
| 19 | raise EmptyException() |
---|
| 20 | |
---|
| 21 | |
---|
| 22 | def main(argv): |
---|
| 23 | times = 1 |
---|
| 24 | total_frames = 1 |
---|
| 25 | if 1 < len(argv): |
---|
| 26 | times = int(argv[1]) |
---|
| 27 | if 2 < len(argv): |
---|
| 28 | total_frames = int(argv[2]) |
---|
| 29 | |
---|
| 30 | start_time = thread_time_ns() |
---|
| 31 | for count in range(times): |
---|
| 32 | try: |
---|
| 33 | unwind_finally(total_frames) |
---|
| 34 | except EmptyException: |
---|
| 35 | pass |
---|
| 36 | |
---|
| 37 | end_time = thread_time_ns() |
---|
| 38 | print('Run-Time (ns):', end_time - start_time) |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | if '__main__' == __name__: |
---|
| 42 | import sys |
---|
| 43 | main(sys.argv) |
---|
Note: See
TracBrowser
for help on using the repository browser.