Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Exceptions performance penalty

Reply
Thread Tools

Exceptions performance penalty

 
 
Michael Andersson
Guest
Posts: n/a
 
      09-02-2003
Hi!
Does the use of exception handling induce a performance penalty during
the execution of non exception handling code?

Regards,
/Michael

 
Reply With Quote
 
 
 
 
Oliver S.
Guest
Posts: n/a
 
      09-02-2003
> Does the use of exception handling induce a performance penalty
> during the execution of non exception handling code?


The performacne-penalty is usually very slight;
not worth to be mentioned.
 
Reply With Quote
 
 
 
 
Peter van Merkerk
Guest
Posts: n/a
 
      09-02-2003
> Does the use of exception handling induce a performance penalty during
> the execution of non exception handling code?


It depends on which compiler yuo are using. There are several ways a
compiler can deal with exceptions so there is no standard answer to this. On
some compilers there is no performance penalty as long as no exception is
thrown. On others there is always a certain performance penalty, even when
no exceptions are thrown.

--
Peter van Merkerk
peter.van.merkerk(at)dse.nl


 
Reply With Quote
 
Hafiz Abid Qadeer
Guest
Posts: n/a
 
      09-03-2003
"Peter van Merkerk" <(E-Mail Removed)> wrote in message news:<bj2u9n$f0ssk$(E-Mail Removed)-berlin.de>...
> > Does the use of exception handling induce a performance penalty during
> > the execution of non exception handling code?

>
> It depends on which compiler yuo are using. There are several ways a
> compiler can deal with exceptions so there is no standard answer to this. On
> some compilers there is no performance penalty as long as no exception is
> thrown. On others there is always a certain performance penalty, even when
> no exceptions are thrown.


In C++ Programming Language 3rd edition section 14.8 Stroustrup writes
that it is possible to implement exception handling in such a way that
there is no run time overhead when no exception is thrown but it is
hard.
There is generally some overhead as we have to keep trach for the
local objects whose constructors have run, so when exception is thrown
their destructors are called. Their is detailed discussion about this
in "More effective C++" by Scott Meyer
 
Reply With Quote
 
Peter van Merkerk
Guest
Posts: n/a
 
      09-03-2003
> > > Does the use of exception handling induce a performance penalty
during
> > > the execution of non exception handling code?

> >
> > It depends on which compiler yuo are using. There are several ways a
> > compiler can deal with exceptions so there is no standard answer to

this. On
> > some compilers there is no performance penalty as long as no

exception is
> > thrown. On others there is always a certain performance penalty,

even when
> > no exceptions are thrown.

>
> In C++ Programming Language 3rd edition section 14.8 Stroustrup writes
> that it is possible to implement exception handling in such a way that
> there is no run time overhead when no exception is thrown but it is
> hard.


It may be hard (but so is writing a C++ compiler), but there are C++
compilers which have implemented zero runtime overhead when no
exceptions are thrown.

> There is generally some overhead as we have to keep trach for the
> local objects whose constructors have run, so when exception is thrown
> their destructors are called. Their is detailed discussion about this
> in "More effective C++" by Scott Meyer


The same book also tells you not to take the performance penalty
estimation too seriously, as thing may improve in the future. This book
is already several years old, and things have improved compared to when
it was written.

The bottom line is that your mileage may vary; it depends on the C++
compiler you are using.

--
Peter van Merkerk
peter.van.merkerk(at)dse.nl



 
Reply With Quote
 
stelios xanthakis
Guest
Posts: n/a
 
      09-03-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (Hafiz Abid Qadeer) wrote in message news:<(E-Mail Removed). com>...
> "Peter van Merkerk" <(E-Mail Removed)> wrote in message news:<bj2u9n$f0ssk$(E-Mail Removed)-berlin.de>...
> > > Does the use of exception handling induce a performance penalty during
> > > the execution of non exception handling code?

> >
> > It depends on which compiler yuo are using. There are several ways a
> > compiler can deal with exceptions so there is no standard answer to this. On
> > some compilers there is no performance penalty as long as no exception is
> > thrown. On others there is always a certain performance penalty, even when
> > no exceptions are thrown.

>
> In C++ Programming Language 3rd edition section 14.8 Stroustrup writes
> that it is possible to implement exception handling in such a way that
> there is no run time overhead when no exception is thrown but it is
> hard.
> There is generally some overhead as we have to keep trach for the
> local objects whose constructors have run, so when exception is thrown
> their destructors are called. Their is detailed discussion about this
> in "More effective C++" by Scott Meyer


AFAIK, this is already done (in g++ at least).

It creates exception tables. From the value of program counter
you can understand in which function/scope you're in. For each
scope you already know which destructors have to be called and
using the stack address you delete the apropriate objects.

We suppose that you can get __builtin_return_address (LEVEL)
and __builtin_frame_address (LEVEL) for the ESP and EPC of the
caller of level LEVEL.

stelios
 
Reply With Quote
 
Alex Vinokur
Guest
Posts: n/a
 
      09-03-2003
Michael Andersson <(E-Mail Removed)> wrote in message news:<JR65b.26667$(E-Mail Removed)>...
> Hi!
> Does the use of exception handling induce a performance penalty during
> the execution of non exception handling code?
>
> Regards,
> /Michael


See similar thread on news:comp.lang.c++.moderated :
http://groups.google.com/groups?th=6b04463d1953921f

=====================================
Alex Vinokur
(E-Mail Removed)
http://mathforum.org/library/view/10978.html
=====================================
 
Reply With Quote
 
Oliver S.
Guest
Posts: n/a
 
      09-03-2003
> AFAIK, this is already done (in g++ at least).
>
> It creates exception tables. From the value of program counter
> you can understand in which function/scope you're in. For each
> scope you already know which destructors have to be called and
> using the stack address you delete the apropriate objects.


That's something I already thought of and I had the idea that the
supporting data-structure would make it possible to determine which
exception-specifiers take effect when the exception is thrown so that
ESs could be supported without any peformance penalty ! That wouldn't
be a reason to love the callow ES-concept, but I think that when the
performance-decreasing effect could be eliminated, they clearly would
be an advantage.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Function pointers: performance penalty? Rui Maciel C Programming 107 10-27-2009 09:27 PM
dereferencing performance penalty? Rui Maciel C Programming 7 07-30-2009 06:06 PM
Integer promotions and performance penalty Sune C Programming 2 10-02-2007 11:06 AM
Performance penalty for encapsulations ?? Yuri Victorovich C++ 1 09-06-2003 06:56 PM
Is there Performance Penalty for multiple cross-assembly-calls? Peter Bär ASP .Net 2 07-18-2003 03:17 AM



Advertisments