@profile
def fizzbuzz(n):
if n % 3 == 0 and n % 5 == 0:
return 'FizzBuzz'
$ kernprof -l fizzbuzz.py
1
2
Fizz
...(省略)...
97
98
Fizz
Wrote profile results to fizzbuzz.py.lprof
$ python -m line_profiler fizzbuzz.py.lprof
Timer unit: 1e-06 s
Total time: 0.000275 s
File: fizzbuzz.py
Function: fizzbuzz at line 5
Line # Hits Time Per Hit % Time Line Contents
==============================================================
5 @profile
6 def fizzbuzz(n):
7 99 116 1.2 42.2 if n % 3 == 0 and n % 5 == 0:
blog.amedama.jp
その他の profile 手法がまとめてあった
qiita.com