Re: weblogsping.py error handling patch

"Blake Winton" <blake-dlUKtbW3TlBcVw/[email protected]>
Newsgroups gmane.comp.web.pyblosxom.devel
Message-ID <[email protected]>
Will wrote:
> Say you wrapped each cb_ function call in a callback list in 
> a try/except block.  First off, you're incurring a 
> performance decrease because try/except blocks are somewhat 
> expensive.

Really?

http://mail.python.org/pipermail/python-list/2001-May/045621.html

(It seems that it's not the try block that's slow, it's the throwing
 of the exception...)

My experiments confirm this hypothesis...

----------------------
import time

def timeIt( func ):
    start = time.time()
    for i in xrange( 1000 ):
        name = func()
    end = time.time()
    print '%s took %5.4f seconds'%(name, end - start)

def base():
    j = 0
    for i in xrange(10000):
        j = i+1
    return j

def tryblock():
    j = 0
    for i in xrange(10000):
        try:
            j = i + 1
        except TypeError, e:
            pass
    return j

timeIt( base )
timeIt( tryblock )
----------------------
(From the above code)
10000 took 1.2830 seconds
10000 took 1.7450 seconds
----------------------
(From another run, of 10 times as many tests...)
10000 took 9.5540 seconds
10000 took 13.6610 seconds
----------------------

So, ya know, for 10,000,000 try blocks, it took 0.462 seconds.
Not all that expensive, I don't think...

Later,
Blake.

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.