optimization question

Kristian Ovaska kristian.ovaska at helsinki.fi
Mon Aug 12 15:56:57 CEST 2002

"Matt Gerrans" <mgerrans at mindspring.com>:
>I concur.   In fact, call me crazy, but I think it is fun to first get
>something working, then chisel away at the slow parts (if necessary) and
>watch as the performance improves.   The profile module make this a

I find this fun, too. And it's good to save the profile stats so you
can read afterwards exactly how the performance was improved. (If
you're into that kind of stuff.)

I'm using this script to do the profiling and printing of stats:

--- <profiler.py> ---

import profile, pstats, os, sys

TMPFILE = 'py-profile-tmp-stats'

def main(args):
    if not args:
        print 'Usage: profiler <module> [args-for-module]'

    module = args[0]
    sys.argv = sys.argv[1:]
    profile.run('execfile("%s")' % module, TMPFILE)

    stats = pstats.Stats(TMPFILE)
    stats.print_stats('^[^<].*', 25)

    if os.path.exists(TMPFILE):

if __name__=='__main__':

--- </profiler.py> ---

Kristian Ovaska <kristian.ovaska at helsinki.fi>

More information about the Python-list mailing list