On Fri, Mar 19, 2010 at 11:07 AM, Conor Walsh <[email protected]> wrote:
>> I _am_ telling you I think exceptions are faster than other control
>> structures _In_ _Some_ _Cases_.
>>
>> I'm happy to explain & clarify if I am unclear.
>
> I'm curious.
>
> Maybe I'm out of my depth, pun not intended, but I was under the impression
> that thrown exceptions have to unwind the stack anyway.  Is there some way
> exceptions are usually implemented that doesn't cost as much as unwinding
> the stack one level at a time?  It seems like 3-or-300 does matter, in that
> you have to check for and possibly call some number of destructors or risk
> leaking all over the place.

The issue is this.  If you don't use exceptions then you have to have
if checks on every return for exceptional conditions.  Those checks
are individually fast, but there are a lot of them.  If there are a
great number of needed checks per exceptional condition, then it is
faster overall to remove those checks and throw an exception when
needed.  Even though it is slower when you throw that exceptions.

In a desktop environment this makes sense.  However in some other
contexts, such as real time embedded programming, it likely doesn't.
And the issue there is the difference between average running time and
worst case running time.

You can see the same issue with, for example, using a hash as a data
structure.  Average access time for a hash is O(1).  Worst case is
O(n).  In many environments hashes make sense.  But if you're looking
to guarantee that you finish in a particular time slice, hashes are a
simply terrible data structure.

> This is a fantastic discussion and I'm happy to see it here.

It is surprisingly involved and detailed.  I've been happy to read through it.

Ben

_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to