The profile module is a standard Python profiler. And with the help of profile module we can run the profiler from the command line. For example you can see the below code.
#!/usr/bin/python
vara = 17
varb = 400
sum = vara + varb
print "vara + varb = %d" % sum
Now, try running cProfile.py over this file sum.py as follows
$cProfile.py sum.py
vara + varb = 417
4 function calls in 0.000 CPU seconds
Note: Ordered by: standard name
Output:
ncalls tottime percall cumtime percall filename:lineno
1 0.000 0.000 0.000 0.000 :1()
1 0.000 0.000 0.000 0.000 sum.py:3()
1 0.000 0.000 0.000 0.000 {execfile}
1 0.000 0.000 0.000 0.000 {method ......}
0 Comment(s)