Python profiling
Simple example
Get data
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# example from __main__.py
import cProfile
from pstats import Stats, SortKey
from my_module.script import add_func
def run_script():
# call your function with some dummy data
print(add_func(2,1))
if __name__ == '__main__':
do_profiling = True
if do_profiling:
with cProfile.Profile() as pr:
run_script()
with open('profiling_stats.txt', 'w') as stream:
stats = Stats(pr, stream=stream)
stats.strip_dirs()
stats.sort_stats('time')
stats.dump_stats('.prof_stats')
stats.print_stats()
else:
start_game()Render data
- You may use a tool like SnakViz
Extensions on VSCodium
- PyVmMonitor, if you already have PyVmMonitor in your device.
- Austin visualizer, if you have already installed Austin on yor device.