お世話になります。
list_bench.pyを下記の内容で保存しました
# -*- coding: utf-8 -*- import profile def bench1(list1, list2): list1 += list2 return list1 def bench2(list1, list2): list3 = list1 + list2 return list3 def loop(bench): for i in range(10000): bench([1,] *i, [2,] * i) if __name__ =='__main__': loop(bench1) loop(bench2)
そして
python -m profile list_bench.pyを実行しましたら結果を得ることができました
20012 function calls in 1.767 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.000 0.000 :0(hasattr)
2 0.000 0.000 0.000 0.000 :0(range)
1 0.018 0.018 0.018 0.018 :0(setprofile)
1 0.001 0.001 1.749 1.749 list_bench.py:2(<module>)
10000 0.127 0.000 0.127 0.000 list_bench.py:3(bench1)
10000 0.257 0.000 0.257 0.000 list_bench.py:6(bench2)
2 1.362 0.681 1.746 0.873 list_bench.py:9(loop)
1 0.000 0.000 0.000 0.000 profile.py:111(Profile)
1 0.000 0.000 0.000 0.000 profile.py:369(fake_code)
1 0.000 0.000 0.000 0.000 profile.py:379(fake_frame)
1 0.002 0.002 0.002 0.002 profile.py:9(<module>)
1 0.000 0.000 1.767 1.767 profile:0(<code object <module>
at 0000000002B8E2B0, file "list_bench.py", line 2>)
0 0.000 0.000 profile:0(profiler)
プログラムファイルが別のファイルを使用している場合でも追跡ができる
tottimeの降順で表示したい場合は”-s”オプションを指定する
C:\Users\mtg-1>python -m profile -s list_bench.py
Traceback (most recent call last):
File "C:\Users\mtg-1\Anaconda2\lib\runpy.py", line 174, in _run_module_as_main
"main", fname, loader, pkg_name)
File "C:\Users\mtg-1\Anaconda2\lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Users\mtg-1\Anaconda2\lib\profile.py", line 610, in <module>
main()
File "C:\Users\mtg-1\Anaconda2\lib\profile.py", line 605, in main
parser.print_usage()
File "C:\Users\mtg-1\Anaconda2\lib\optparse.py", line 1603, in print_usage
print >>file, self.get_usage()
File "C:\Users\mtg-1\Anaconda2\lib\optparse.py", line 1589, in get_usage
self.expand_prog_name(self.usage))
File "C:\Users\mtg-1\Anaconda2\lib\optparse.py", line 1566, in expand_prog_name
return s.replace("%prog", self.get_prog_name())
File "C:\Users\mtg-1\Anaconda2\lib\optparse.py", line 1561, in get_prog_name
return os.path.basename(sys.argv[0])
IndexError: list index out of range
エラーの意味が分かりませんのでお教えください
回答3件
あなたの回答
tips
プレビュー