silas (owner)

Revisions

gist: 119114 Download_button fork
public
Public Clone URL: git://gist.github.com/119114.git
Text only
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
==
== Build and install
==
 
http://silassewell.googlecode.com/files/python-line_profiler-1.0-0.1.b2.fc10.src.rpm
 
==
== Create file "test.py" with the following content
==
 
import random, time
 
def sleep():
    seconds = random.randint(0, 5)
    print 'Sleeping %s seconds' % seconds
    time.sleep(seconds)
 
@profile
def test():
    sleep()
    sleep()
    sleep()
 
test()
 
==
== Run and profile
==
 
[silas@silas ~]$ kernprof.py -l test.py
Sleeping 4 seconds
Sleeping 5 seconds
Sleeping 2 seconds
Wrote profile results to test.py.lprof
 
==
== View results
==
 
[silas@silas ~]$ python -m line_profiler test.py.lprof
Timer unit: 1e-06 s
 
File: test.py
Function: test at line 8
Total time: 10.9994 s
 
Line # Hits Time Per Hit % Time Line Contents
==============================================================
     8 @profile
     9 def test():
    10 1 3999416 3999416.0 36.4 sleep()
    11 1 4999982 4999982.0 45.5 sleep()
    12 1 1999990 1999990.0 18.2 sleep()