Exceptions performance penalty

Discussion in 'C++' started by Michael Andersson, Sep 2, 2003.

  1. Hi!
    Does the use of exception handling induce a performance penalty during
    the execution of non exception handling code?

    Regards,
    /Michael
     
    Michael Andersson, Sep 2, 2003
    #1
    1. Advertising

  2. Michael Andersson

    Oliver S. Guest

    > 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.
     
    Oliver S., Sep 2, 2003
    #2
    1. Advertising

  3. > 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
     
    Peter van Merkerk, Sep 2, 2003
    #3
  4. "Peter van Merkerk" <> wrote in message news:<bj2u9n$f0ssk$-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
     
    Hafiz Abid Qadeer, Sep 3, 2003
    #4
  5. > > > 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
     
    Peter van Merkerk, Sep 3, 2003
    #5
  6. (Hafiz Abid Qadeer) wrote in message news:<>...
    > "Peter van Merkerk" <> wrote in message news:<bj2u9n$f0ssk$-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
     
    stelios xanthakis, Sep 3, 2003
    #6
  7. Michael Andersson

    Alex Vinokur Guest

    Alex Vinokur, Sep 3, 2003
    #7
  8. Michael Andersson

    Oliver S. Guest

    > 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.
     
    Oliver S., Sep 3, 2003
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Bär
    Replies:
    2
    Views:
    430
    Yan-Hong Huang[MSFT]
    Jul 18, 2003
  2. Yuri Victorovich

    Performance penalty for encapsulations ??

    Yuri Victorovich, Sep 6, 2003, in forum: C++
    Replies:
    1
    Views:
    344
    Kevin Goodsell
    Sep 6, 2003
  3. Sune
    Replies:
    2
    Views:
    347
    Martin Wells
    Oct 2, 2007
  4. Rui Maciel

    dereferencing performance penalty?

    Rui Maciel, Jul 27, 2009, in forum: C Programming
    Replies:
    7
    Views:
    1,578
    Antoninus Twink
    Jul 30, 2009
  5. Rui Maciel

    Function pointers: performance penalty?

    Rui Maciel, Oct 11, 2009, in forum: C Programming
    Replies:
    107
    Views:
    4,092
    Sjouke Burry
    Oct 27, 2009
Loading...

Share This Page