-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
49 lines (33 loc) · 757 Bytes
/
example.py
File metadata and controls
49 lines (33 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from time import sleep
import cProfile
import sys
def main():
child_a()
child_a()
child_b()
def child_a():
print('In A')
sleep(1)
def child_b():
print('In B')
sleep(1)
grandchild_c()
grandchild_d()
def grandchild_c():
print('In C')
sleep(1)
def grandchild_d():
print('In D')
sleep(1)
if __name__ == '__main__':
if len(sys.argv) == 2 and sys.argv[1] == '--self-profile':
profiler = cProfile.Profile()
output_file = 'output.prof'
print('Starting self-profiling...')
profiler.enable()
main()
profiler.disable()
profiler.dump_stats(output_file)
print(f'...finished, wrote output to "{output_file}"')
else:
main()