Python Profiling/Python性能评估

文章目录
  1. 1. memory_profiler

性能主要包括两方面:时间和空间

Python性能调优相关的库

  1. memory_profiler:可评估 .py 文件
  2. filprofiler:可评估文件和jupyter notebook中的代码

memory_profiler

1
2
3
4
5
6
7
8
9
10
# sample.py
from memory_profiler import profile

@profile
def run():
# TODO: Replace with code to benchmark
print('do work!')

if __name__ == "__main__":
run()
1
2
3
4
5
6
7
8
9
10
JinlongLi (master *) folder $ python sample.py
do work!
Filename: sample.py

Line # Mem usage Increment Occurences Line Contents
============================================================
10 39.9 MiB 39.9 MiB 1 @profile
11 def run():
12 # TODO:
13 39.9 MiB 0.0 MiB 1 print('do work!')