0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

pythonのmemory_profilerが重いので計測してみた

0
Posted at

スペック

MacBook Air
OS X El Capitan
プロセッサ 1.4GHz Intel Cor i5
メモリ 4GB 1600 MHz DDR3

インストール

https://yakst.com/ja/posts/42
を参考に

pip install -U memory_profiler
pip install psutil

計測用スクリプト

1万回数を数えるだけ

1. メモリ測定なし用

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()

2. メモリ測定あり用
main関数の前に"@profile"を挿入しただけ

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()

測定結果

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

350倍くらい違う。
使い方が悪いのかなぁ

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?