perfomance penalty in using execption handling..

Discussion in 'C++' started by A. Saksena, Sep 10, 2004.

  1. A. Saksena

    A. Saksena Guest

    Hi,
    Do anybody have an idea of the performance penalty while using exception
    handling (specially with g++)

    Abhishek
    A. Saksena, Sep 10, 2004
    #1
    1. Advertising

  2. A. Saksena

    Phlip Guest

    A. Saksena wrote:

    > Do anybody have an idea of the performance penalty while using exception
    > handling (specially with g++)


    Can you write a few functions, call them 10,000 times, time test them, and
    run them with and without exception handling turned on in the compiler?

    (And why do you need performance?)

    --
    Phlip
    http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces
    Phlip, Sep 10, 2004
    #2
    1. Advertising

  3. A. Saksena

    void Guest

    A. Saksena wrote:
    > Hi,
    > Do anybody have an idea of the performance penalty while using exception
    > handling (specially with g++)


    I've done some small tests you can look at it here:
    http://3miasto.net/~chq/c/carray.txt

    Best
    Darek
    void, Sep 10, 2004
    #3
  4. http://www.codeproject.org/cpp/exceptionhandler.asp#xx515459xx
    lots of compilers do not pay any performance penalty, unless an exception
    is thrown... So if you code that way, that exceptions are truly exceptional,
    you should
    have no penalty...
    " A. Saksena" <> wrote in message
    news:chsdl5$f4e$...
    > Hi,
    > Do anybody have an idea of the performance penalty while using exception
    > handling (specially with g++)
    >
    > Abhishek
    >
    >
    Jesper Madsen, Sep 10, 2004
    #4
  5. Jesper Madsen wrote:

    > http://www.codeproject.org/cpp/exceptionhandler.asp#xx515459xx
    > lots of compilers do not pay any performance penalty, unless an exception
    > is thrown... So if you code that way, that exceptions are truly
    > exceptional, you should
    > have no penalty...


    "For this discussion, I will consider exceptions to be those that are
    explicitly thrown or occur due to conditions like divide by zero or null
    pointer access."

    C++ programmers catching null pointer exceptions? I'll let you know when I
    stop laughing. :-D

    --
    "[M]y dislike for the preprocessor is well known. Cpp is essential in C
    programming, and still important in conventional C++ implementations, but
    it is a hack, and so are most of the techniques that rely on it. ...I think
    the time has come to be serious about macro-free C++ programming." - B. S.
    Steven T. Hatton, Sep 11, 2004
    #5
  6. "Steven T. Hatton" <> skrev i en meddelelse
    news:...
    >
    > "For this discussion, I will consider exceptions to be those that are
    > explicitly thrown or occur due to conditions like divide by zero or null
    > pointer access."
    >
    > C++ programmers catching null pointer exceptions? I'll let you know when

    I
    > stop laughing. :-D
    >


    Visual C++ in its standard configuration allow null-pointer exceptions to be
    catched, so there's not really much to laugh at. And if you continue your
    laughs, I can tell you that this is completely compliant.

    Apart from that, the link seems to be about what Microsoft calls "structured
    exception handling" (a bit like Unix signals). I only skimmed that page,
    however.

    /Peter
    Peter Koch Larsen, Sep 11, 2004
    #6
  7. A. Saksena

    Old Wolf Guest

    "Peter Koch Larsen" <> wrote:
    > "Steven T. Hatton" <> skrev i en meddelelse:

    (whatever that means)
    > >
    > > "For this discussion, I will consider exceptions to be those that are
    > > explicitly thrown or occur due to conditions like divide by zero or null
    > > pointer access."
    > >
    > > C++ programmers catching null pointer exceptions?
    > > I'll let you know when I stop laughing. :-D

    >
    > Visual C++ in its standard configuration allow null-pointer
    > exceptions to be catched,


    Null pointer accesses don't generate an exception.
    Maybe you mean that Visual C++ generates an exception for null-pointer
    accesses?

    > And if you continue your laughs, I can tell you that this is
    > completely compliant.


    This means it would have to check every single pointer
    access (and every division, if it also generates exceptions for
    divide-by-zero), so in the context of the OP's question
    "what overhead?", the answer would have to be "a lot".
    Old Wolf, Sep 12, 2004
    #7
  8. "Old Wolf" <> skrev i en meddelelse
    news:...
    > "Peter Koch Larsen" <> wrote:
    > > "Steven T. Hatton" <> skrev i en meddelelse:

    > (whatever that means)
    > > >
    > > > "For this discussion, I will consider exceptions to be those that are
    > > > explicitly thrown or occur due to conditions like divide by zero or

    null
    > > > pointer access."
    > > >
    > > > C++ programmers catching null pointer exceptions?
    > > > I'll let you know when I stop laughing. :-D

    > >
    > > Visual C++ in its standard configuration allow null-pointer
    > > exceptions to be catched,

    >
    > Null pointer accesses don't generate an exception.
    > Maybe you mean that Visual C++ generates an exception for null-pointer
    > accesses?
    >
    > > And if you continue your laughs, I can tell you that this is
    > > completely compliant.

    >
    > This means it would have to check every single pointer
    > access (and every division, if it also generates exceptions for
    > divide-by-zero), so in the context of the OP's question
    > "what overhead?", the answer would have to be "a lot".


    No - you are misunderstanding my post - especially the part you snipped ;-)

    I am saying that one legal behaviour of dereferencing a null pointer is to
    throw an exception. This is so because the behaviour in this case - and
    other cases of this nature - is unspecified: anything can happen.

    /Peter
    Peter Koch Larsen, Sep 13, 2004
    #8
  9. A. Saksena

    Old Wolf Guest

    "Peter Koch Larsen" <> wrote:
    > "Old Wolf" <> skrev i en meddelelse:
    > > "Peter Koch Larsen" <> wrote:
    > > > "Steven T. Hatton" <> skrev i en meddelelse:
    > > > >
    > > > > "For this discussion, I will consider exceptions to be those that are
    > > > > explicitly thrown or occur due to conditions like divide by zero or

    > null
    > > > > pointer access."
    > > > >
    > > > > C++ programmers catching null pointer exceptions?
    > > > > I'll let you know when I stop laughing. :-D
    > > >
    > > > Visual C++ in its standard configuration allow null-pointer
    > > > exceptions to be catched,

    > >
    > > Null pointer accesses don't generate an exception.
    > > Maybe you mean that Visual C++ generates an exception for null-pointer
    > > accesses?
    > >
    > > > And if you continue your laughs, I can tell you that this is
    > > > completely compliant.

    > >
    > > This means it would have to check every single pointer
    > > access (and every division, if it also generates exceptions for
    > > divide-by-zero), so in the context of the OP's question
    > > "what overhead?", the answer would have to be "a lot".

    >
    > No - you are misunderstanding my post - especially the part you snipped ;-)
    >
    > I am saying that one legal behaviour of dereferencing a null pointer is to
    > throw an exception. This is so because the behaviour in this case - and
    > other cases of this nature - is unspecified: anything can happen.
    >

    Yes, we all know that. What has that got to do with whether it is
    laughable to capture null pointer exceptions? So I snipped parts
    related to that.
    I repeat the assertion of Steven T. Hatton:

    > > > > C++ programmers catching null pointer exceptions?
    > > > > I'll let you know when I stop laughing. :-D


    I agree, you seem to disagree, why? (The fact that null pointer
    exceptions exist does not imply that catching them is not laughable).
    Old Wolf, Sep 13, 2004
    #9
  10. "Old Wolf" <> skrev i en meddelelse
    news:...
    > "Peter Koch Larsen" <> wrote:
    > > "Old Wolf" <> skrev i en meddelelse:
    > > > "Peter Koch Larsen" <> wrote:


    [snip]
    > > >
    > > > This means it would have to check every single pointer
    > > > access (and every division, if it also generates exceptions for
    > > > divide-by-zero), so in the context of the OP's question
    > > > "what overhead?", the answer would have to be "a lot".


    Why the above statement if You do not believe that C++ should throw in case
    of accessing a null pointer? That is how i took and - until i saw your "we
    all know that" remark later.
    Please note that i have not in any post (in this thread or elsewhere)
    indicated that the throw was sensible.

    > >
    > > No - you are misunderstanding my post - especially the part you snipped

    ;-)
    > >
    > > I am saying that one legal behaviour of dereferencing a null pointer is

    to
    > > throw an exception. This is so because the behaviour in this case - and
    > > other cases of this nature - is unspecified: anything can happen.
    > >

    > Yes, we all know that. What has that got to do with whether it is
    > laughable to capture null pointer exceptions? So I snipped parts
    > related to that.


    It is not so laughable to catch these if they are thrown, is it? There are
    situations where a catch (...) is justified and in these situations you
    will - with a given configuration of some compilers - catch null pointer
    exceptions and stuff like that.

    > I repeat the assertion of Steven T. Hatton:
    >
    > > > > > C++ programmers catching null pointer exceptions?
    > > > > > I'll let you know when I stop laughing. :-D

    >
    > I agree, you seem to disagree, why? (The fact that null pointer
    > exceptions exist does not imply that catching them is not laughable).


    Well - let us just agree that our sense of humour differs, then ;-)

    Peter
    Peter Koch Larsen, Sep 14, 2004
    #10
    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:
    409
    Yan-Hong Huang[MSFT]
    Jul 18, 2003
  2. =?Utf-8?B?Q3NoYXJwR3V5?=

    security execption

    =?Utf-8?B?Q3NoYXJwR3V5?=, Feb 23, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    1,301
    S. Justin Gengo [MCP]
    Feb 27, 2006
  3. Michael Andersson

    Exceptions performance penalty

    Michael Andersson, Sep 2, 2003, in forum: C++
    Replies:
    7
    Views:
    540
    Oliver S.
    Sep 3, 2003
  4. Yuri Victorovich

    Performance penalty for encapsulations ??

    Yuri Victorovich, Sep 6, 2003, in forum: C++
    Replies:
    1
    Views:
    324
    Kevin Goodsell
    Sep 6, 2003
  5. News123
    Replies:
    4
    Views:
    398
    News123
    Mar 20, 2010
Loading...

Share This Page