[Zope-Coders] SimpleItem.getId busted

Donovan Baarda abo at minkirri.apana.org.au
Thu Nov 20 21:53:49 EST 2003


On Fri, 2003-11-21 at 03:00, Paul Winkler wrote:
[...]
> The change of hasattr / getattr to try/except is a bit gratuitous and
> unrelated to the intent of your fix. I was curious if there's a performance
> difference (you reminded me that I've always wondered about this),
> so I did a bit of quick and dirty benchmarking. In python 2.1.3 and 2.2.3, 
> try/except is about 50% faster when the try succeeds, but 50% slower 
> when the exception is raised.  Six of one, half a dozen of the other...

I remember reading some benchmark stuff on python 1.5 years ago that
discussed how using exceptions for rarely executed paths is much more
efficient than using if statements... looks like it's still true, which
makes sense. Python's exception detection/handling mechanism's are
"always on" anyway, so most of the exception overheads will be in place
even when you don't use them, unlike other languages where exceptions
only work properly inside "try" statements.

I also remember a philosophical argument thread about "when is using
exceptions appropriate", with one side arguing "only use them for things
that should never happen", and the other arguing "abnormal behaviour is
relative, even terminating a loop is an exception from the point of view
of the loop". In the end I think the language you use determines what is
appropriate, and Python certainly leans towards the latter philosophy.
Exceptions good :-)

-- 
Donovan Baarda <abo at minkirri.apana.org.au>
http://minkirri.apana.org.au/~abo/




More information about the Zope-Coders mailing list