Profiling programs/scripts?

Aaron Watters aaron.watters at gmail.com
Fri Apr 11 15:22:06 EDT 2008


On Apr 11, 2:49 pm, skanem... at yahoo.se wrote:
> how do i profile a program? i found out that there are some profilers
> included in the standard library but couldnt really figure out how to
> access/use them

I put this at the bottom of my main module:

=== cut
if __name__=="__main__":
    try:
        from cProfile import run
    except:
        from profile import run
    run("tests()")
=== cut

Here tests() is the function I want to profile.  The cProfile
module, when available is better than the older profile module,
but it's only available in very recent Python installations.
The profile "run" function will run the tests function and print
a report on the timings and counts it found.

More info here:
  http://docs.python.org/lib/profile.html

  -- Aaron Watters
===
http://www.xfeedme.com/nucular/pydistro.py/go?FREETEXT=emulate+perl



More information about the Python-list mailing list