source: doc/theses/andrew_beach_MMath/code/throw-empty.py @ 3d618a0

Last change on this file since 3d618a0 was b183717, checked in by Andrew Beach <ajbeach@…>, 3 years ago

Update another file in the exception benchmarks as well as some print formatting.

  • Property mode set to 100755
File size: 759 bytes
Line 
1#!/usr/bin/env python3
2
3# Throw Across Empty Function
4
5from time import thread_time_ns
6
7
8class EmptyException(Exception):
9    pass
10
11
12def unwind_empty(frames):
13    if 0 < frames:
14        unwind_empty(frames - 1)
15    else:
16        raise EmptyException()
17
18
19def main(argv):
20    times = 1
21    total_frames = 1
22    if 1 < len(argv):
23        times = int(argv[1])
24    if 2 < len(argv):
25        total_frames = int(argv[2])
26
27    start_time = thread_time_ns()
28    for count in range(times):
29        try:
30            unwind_empty(total_frames)
31        except EmptyException:
32            pass
33
34    end_time = thread_time_ns()
35    print('Run-Time (s): {:.1f}'.format((end_time - start_time) / 1_000_000_000.))
36
37
38if '__main__' == __name__:
39    import sys
40    main(sys.argv)
Note: See TracBrowser for help on using the repository browser.