[Tutor] Understanding cProfile output
ranveer raghuwanshi
ranveer.raghu at gmail.com
Thu Sep 20 20:58:36 CEST 2012
Hi,
I am trying to understand the output of cProfile when run against my python
code. The code is:
from math import floor,sqrt
count = int(floor(sqrt(100000)))
max_check = range(2,count+1)
original_list = range(2,100001)
for j in max_check:
temp_list=[]
for i in original_list:
if i%j==0 and j<i:
temp_list.append(i)
else:
pass
original_list = list(set(original_list) - set(temp_list))
temp_list = []
print len(original_list)
What the above code does is it counts the number of prime numbers less than
1,00,000.
Now when I profile this code using *python -m cProfile -s time
countPrime.py. *The output I get is http://sprunge.us/SOEj. Now what I
don't understand is what it means by *tottime=16.374 for function
countPrime.py:1(<module>). *I understand fine that it took around *0.320s
for method append.*
So, is 16.374 the total time my scripts takes but according to profiler the
total time is 16.705.
--
Ranveer Raghuwanshi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120921/49b0c94b/attachment.html>
More information about the Tutor
mailing list