This is a very basic example which demonstrates the python profiler:
- import profile
-
-
def counterTest():
-
"""Count from 1 to 100000 using the
-
append instruction
-
"""
-
Counter = []
-
for i in range(100000):
-
Counter.append(i)
-
return Counter
-
-
print "Profile for counterTest, print the CPU time it took to count from 1 to 100000\n"
-
profile.run('counterTest()')
The output looks like:
Profile for counterTest, print the CPU time it took to count from 1 to 100000
100005 function calls in 1.226 CPU seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
100000 0.549 0.000 0.549 0.000 :0(append)
1 0.012 0.012 0.012 0.012 :0(range)
1 0.000 0.000 0.000 0.000 :0(setprofile)
1 0.009 0.009 1.225 1.225 <string>:1(?)
1 0.656 0.656 1.216 1.216 prof_example.py:3(counterTest)
1 0.000 0.000 1.226 1.226 profile:0(counterTest())
0 0.000 0.000 profile:0(profiler)