Since memory_profiler of python is heavy, I measured it

spec

MacBook Air OS X El Capitan Processor 1.4GHz Intel Core i5 Memory 4GB 1600 MHz DDR3

Installation

https://yakst.com/ja/posts/42 With reference to

pip install -U memory_profiler
pip install psutil

Measurement script

Just count 10,000 times

  1. For no memory measurement

count10k.py


#!/usr/bin/env python
import time

def main():
	start = time.time()
	j = 0
	for i in range(10000):
		j += 1
	print ("elapsed_time:{0}".format(time.time() - start)) + "[sec]"

if __name__ == "__main__": main()
  1. For memory measurement I just inserted "@profile" before the main function

mem_count10k.py


#!/usr/bin/env python
import time
@profile
def main():
	start = time.time()
	j = 0
	for i in range(10000):
		j += 1
	print ("elapsed_time:{0}".format(time.time() - start)) + "[sec]"

if __name__ == "__main__": main()

Measurement result

$ python count10k.py
elapsed_time:0.00121402740479[sec]
$ python -m memory_profiler mem_count10k.py
elapsed_time:0.404528856277[sec]

It's about 350 times different. I wonder if it's bad to use

Recommended Posts

Since memory_profiler of python is heavy, I measured it
Since Python 1.5 of Discord, I can't get a list of members
I measured various methods of interprocess communication in multiprocessing of python3
Since there is no Japanese explanation around Permission of Django REST Framework, I wrote it
What is Python? What is it used for?
[Super basics of Python] I learned the basics of the basics, so I summarized it briefly.
The latest NGINX is an application server! ?? I measured the benchmark of NGINX Unit with PHP, Python, Go! !!
I did a lot of research on how Python is executed
Since it is the 20th anniversary of the formation, I tried to visualize the lyrics of Perfume with Word Cloud
Find out the name of the method that called it from the method that is python
I measured the speed of list comprehension, for and while with python2.7.
What kind of programming language is Python?
I didn't know the basics of Python
[python] [meta] Is the type of python a type?
[Python] Complete preprocessing Memo as it is
The Python project template I think of.
Wrangle x Python book I tried it [1]
CheckIO (Python)> Non-unique Elements> I implemented it
In Python, change the behavior of the method depending on how it is called
Since python is read as "Pichon", it can be executed with "Pichon" (it is a story)
"Brute force of MD5 hash value of 6-digit password" I tried it with Python
[Python / DynamoDB / boto3] List of operations I tried
I tried hundreds of millions of SQLite with python
[Python] I introduced Word2Vec and played with it.
The answer of "1/2" is different between python2 and 3
When I try matplotlib in Python, it says'cairo.Context'
I tried Python! ] I graduated today from "What is Python! Python!"!
Try the free version of Progate [Python I]
This is the only basic review of Python ~ 1 ~
This is the only basic review of Python ~ 2 ~
I touched some of the new features of Python 3.8 ①
This is the only basic review of Python ~ 3 ~
I / O related summary of python and fortran
Judge whether it is a prime number [Python]
[Python Data Frame] When the value is empty, fill it with the value of another column.
Since choreography is Wakaran, I will implement it and release the entire source code.
Image processing with Python (I tried binarizing it into a mosaic art of 0 and 1)
I thought about why Python self is necessary with the feeling of a Python interpreter