[Tutor] Understanding cProfile output
ranveer raghuwanshi
ranveer.raghu at gmail.com
Thu Sep 20 23:15:26 CEST 2012
Thanks for the input everyone.
@Dave, I basically implemented the sieve of eratosthenes to fiind the
number of prime numbers in a given range. So, yes I am looking for
suggestions to speed it up.
On Fri, Sep 21, 2012 at 2:16 AM, Dave Angel <d at davea.name> wrote:
> On 09/20/2012 03:56 PM, Steven D'Aprano wrote:
> > On 21/09/12 04:58, ranveer raghuwanshi wrote:
> >> Hi,
> >>
> >> I am trying to understand the output of cProfile when run against my
> >> python
> >> code. The code is:
> > [...]
> >> 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.
> > <SNIP>
> >
> > #result9592
> > 90414 function calls in 16.705 seconds
> >
> > Ordered by: internal time
> >
> > ncalls tottime percall cumtime percall filename:lineno(function)
> > 1 16.374 16.374 16.705 16.705 countPrime.py:1(<module>)
> > 90407 0.320 0.000 0.320 0.000 {method 'append' of
> > 'list' objects}
> > 2 0.011 0.005 0.011 0.005 {range}
> > 1 0.000 0.000 0.000 0.000 {math.sqrt}
> > 1 0.000 0.000 0.000 0.000 {math.floor}
> > 1 0.000 0.000 0.000 0.000 {len}
> > 1 0.000 0.000 0.000 0.000 {method 'disable' of
> > '_lsprof.Profiler' objects}
> >
> > <SNIP>
> >
> >
> >> 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.
> >
> I don't know the Python profiler, but I've worked with many others over
> the years (and even written one). It looks like it follows very
> reasonable conventions in its output.
>
> tottime is the total time spent in that function, including the
> functions it calls. cumtime is the cumulative time spent in that
> function, after deducting for any functions it may have called. So in
> approximate numbers, 16.705 = 16.374 + .320 + .011
>
> Both columns are very useful, as is the ncalls column. However, the net
> result is you didn't learn very much about the efficiency of your
> algorithm.
>
> Are you looking for suggestions for speeding it up? Or suggestions for
> getting more interesting results from profiling?
>
>
>
> --
>
> DaveA
>
>
--
Ranveer Raghuwanshi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120921/bd7b94fd/attachment.html>
More information about the Tutor
mailing list