When looking at memory usage in Python 3

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

reference

memory_profiler

http://www.sakito.com/2012/09/python-memoryprofiler.html

Character code error

http://chidipy.jpn.com/topics/?p=309

Recommended Posts

When looking at memory usage in Python 3
Attention when os.mkdir in Python
Check for memory leaks in Python
Precautions when using pit in Python
[Python] Generate QR code in memory
Behavior when listing in Python heapq
Elementary ITK usage learned in Python
When using regular expressions in Python
When writing a program in Python
When specifying multiple keys in python sort
Memory leak in Python Jupyter Lab (Notebook)?
Precautions when pickling a function in python
Non-logical operator usage of or in python
[Tips] Easy-to-read writing when connecting functions in Python
Check memory usage
Quadtree in Python --2
When codec can't decode byte appears in python
Python in optimization
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Recommended environment and usage when developing with Python
Meta-analysis in Python
Unittest in python
When I try matplotlib in Python, it says'cairo.Context'
One liner to 100% CPU1 core usage in Python
Epoch in Python
Discord in Python
Sudoku in Python
Precautions when dealing with control structures in Python 2.6
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
Character encoding when dealing with files in Python 3
Split files when writing vim plugin in python
python at docker
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
[Question] What happens when I use% in python?
Puyo Puyo in python
python in virtualenv
PPAP in Python
Error when trying to install psycopg2 in Python
Behavior when saving python datetime object in MongoDB
Quad-tree in Python
Solution when module'XXX' has no attribute'XXX' in Python
Reflection in Python