Re: weblogsping.py error handling patch

will guaraldi <[email protected]>
Newsgroups gmane.comp.web.pyblosxom.devel
Message-ID <[email protected]>
Correct me if I'm wrong, but I think the email at that link is talking 
about type checking versus using a try/except block as opposed to using a 
try/except block versus not using one.

What version of Python are you using?  I'm using Python 2.3 on an ibook G4 
(800 mhz) with Mac OS 10.3 and I get:

    10000 took 7.8344 seconds
    10000 took 10.9729 seconds

with the code you posted.  That seems pretty significant to me.  We use 
callbacks in a few places where the runtime is O(n) where n is the number 
of blog entries you have.  If you have several plugins on the same 
callback, then that becomse O(m * n) where m is the number of plugins and 
n is the number of entries, though m is likely < 10.

Does that sound right?

/will


On Tue, 29 Aug 2006, Blake Winton wrote:
> 
> 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.