speedier cgi and perf monitoring

Josiah Carlson jcarlson at uci.edu
Tue Oct 26 01:33:54 EDT 2004


"Eric S. Johansson" <esj at harvee.org> wrote:
> 
> Josiah Carlson wrote:
> > Don't use profiling tools.  Do manual profiling via time.time() calls
> > (which provides wall-clock time). Start coarse, and narrow down your
> > search each iteration.
> 
> I appreciate the kindness of your suggestion and I will hope you will 
> understand when I say it's a sucky option but one I will have to live with.


I personally like to use time-delta classes, they keep some of the
boilerplate code to a minimum.

class delta:
    def __init__(self):
        self.time = time.time()
    def __repr__(self):
        t = time.time()
        delta = self.time-t
        self.time = t
        return repr(delta)

def fun():
    td = delta()
    #do something that takes time
    print "operation ... took %s seconds"%td
    #do something else
    ...

It doesn't give you a one-pass mechanism for determining the exact line
where your script is being borked, but it works.


 - Josiah




More information about the Python-list mailing list