Install the following modules with pip
pip install psutil
pip install memory_profiler
Rewrite the following part to prevent character code error
Python 3.4.3
/home/vagrant/.pyenv/versions/3.4.3/lib/python3.4/site-packages/memory_profiler.py
Line 890
xec(compile(open(__file__, encoding="utf-8").read(), __file__, 'exec'), ns, ns)
How to use
Write @ profile
above the method you want to see memory consumption
Example
#!/usr/bin/env python
# -*- coding: utf-8 -*-
@profile
def main():
a = [1] * (10 ** 6)
b = [2] * (2 * 10 ** 7)
del b
return a
if __name__ == '__main__':
main()
Run below
python -m memory_profiler python filename
memory_profiler
http://www.sakito.com/2012/09/python-memoryprofiler.html
Character code error
http://chidipy.jpn.com/topics/?p=309
Recommended Posts