(no title)
sown | 10 years ago
% cat > l.py
@profile
def slow_func():
for i in xrange(1048576):
continue
return -1
@profile
def fast_func():
for i in xrange(10):
continue
return -1
@profile
def the_func():
for i in xrange(10):
slow_func()
fast_func()
if __name__ == "__main__":
the_func()
% kernprof -l l.py
% python -m line_profiler l.py.lprof
Timer unit: 1e-06 s
Total time: 5.21814 s
File: l.py
Function: slow_func at line 1
Line # Hits Time Per Hit % Time Line Contents
==============================================================
1 @profile
2 def slow_func():
3 10485770 2644263 0.3 50.7 for i in xrange(1048576):
4 10485760 2573875 0.2 49.3 continue
5
6 10 5 0.5 0.0 return -1
Total time: 8.9e-05 s
File: l.py
Function: fast_func at line 8
Line # Hits Time Per Hit % Time Line Contents
==============================================================
8 @profile
9 def fast_func():
10 110 61 0.6 68.5 for i in xrange(10):
11 100 26 0.3 29.2 continue
12
13 10 2 0.2 2.2 return -1
Total time: 10.5501 s
File: l.py
Function: the_func at line 14
Line # Hits Time Per Hit % Time Line Contents
==============================================================
14 @profile
15 def the_func():
16 11 3 0.3 0.0 for i in xrange(10):
17 10 10549853 1054985.3 100.0 slow_func()
18 10 203 20.3 0.0 fast_func()
No comments yet.