Last change
on this file since 4205c07 was b183717, checked in by Andrew Beach <ajbeach@…>, 4 years ago |
Update another file in the exception benchmarks as well as some print formatting.
|
-
Property mode
set to
100755
|
File size:
770 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 main(argv):
|
---|
| 16 | times = 1
|
---|
| 17 | if 1 < len(argv):
|
---|
| 18 | times = int(argv[1])
|
---|
| 19 | if 2 < len(argv):
|
---|
| 20 | should_catch = 0 < int(argv[2])
|
---|
| 21 |
|
---|
| 22 | start_time = thread_time_ns()
|
---|
| 23 | for count in range(times):
|
---|
| 24 | try:
|
---|
[f79ee0d] | 25 | try:
|
---|
| 26 | raise EmptyException()
|
---|
| 27 | except EmptyException as exc:
|
---|
| 28 | if not should_catch:
|
---|
| 29 | raise
|
---|
[63e3ed8] | 30 | except EmptyException:
|
---|
| 31 | pass
|
---|
| 32 |
|
---|
| 33 | end_time = thread_time_ns()
|
---|
[b183717] | 34 | print('Run-Time (s): {:.1f}'.format((end_time - start_time) / 1_000_000_000.))
|
---|
[63e3ed8] | 35 |
|
---|
| 36 |
|
---|
| 37 | if '__main__' == __name__:
|
---|
| 38 | import sys
|
---|
| 39 | main(sys.argv)
|
---|
Note:
See
TracBrowser
for help on using the repository browser.