Exceptions performance penalty

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Andersson

    Exceptions performance penalty

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

    Regards,
    /Michael

  • Oliver S.

    #2
    Re: Exceptions performance penalty

    > Does the use of exception handling induce a performance penalty[color=blue]
    > during the execution of non exception handling code?[/color]

    The performacne-penalty is usually very slight;
    not worth to be mentioned.

    Comment

    • Peter van Merkerk

      #3
      Re: Exceptions performance penalty

      > Does the use of exception handling induce a performance penalty during[color=blue]
      > the execution of non exception handling code?[/color]

      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.merke rk(at)dse.nl


      Comment

      • Hafiz Abid Qadeer

        #4
        Re: Exceptions performance penalty

        "Peter van Merkerk" <merkerk@deadsp am.com> wrote in message news:<bj2u9n$f0 ssk$1@ID-133164.news.uni-berlin.de>...[color=blue][color=green]
        > > Does the use of exception handling induce a performance penalty during
        > > the execution of non exception handling code?[/color]
        >
        > 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.[/color]

        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

        Comment

        • Peter van Merkerk

          #5
          Re: Exceptions performance penalty

          > > > Does the use of exception handling induce a performance penalty
          during[color=blue][color=green][color=darkred]
          > > > the execution of non exception handling code?[/color]
          > >
          > > 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[/color][/color]
          this. On[color=blue][color=green]
          > > some compilers there is no performance penalty as long as no[/color][/color]
          exception is[color=blue][color=green]
          > > thrown. On others there is always a certain performance penalty,[/color][/color]
          even when[color=blue][color=green]
          > > no exceptions are thrown.[/color]
          >
          > 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.[/color]

          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.
          [color=blue]
          > 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[/color]

          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.merke rk(at)dse.nl



          Comment

          • stelios xanthakis

            #6
            Re: Exceptions performance penalty

            hafizabidqadeer @yahoo.com (Hafiz Abid Qadeer) wrote in message news:<9c67da8b. 0309022113.36cc 93b7@posting.go ogle.com>...[color=blue]
            > "Peter van Merkerk" <merkerk@deadsp am.com> wrote in message news:<bj2u9n$f0 ssk$1@ID-133164.news.uni-berlin.de>...[color=green][color=darkred]
            > > > Does the use of exception handling induce a performance penalty during
            > > > the execution of non exception handling code?[/color]
            > >
            > > 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.[/color]
            >
            > 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[/color]

            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_retur n_address (LEVEL)
            and __builtin_frame _address (LEVEL) for the ESP and EPC of the
            caller of level LEVEL.

            stelios

            Comment

            • Alex Vinokur

              #7
              Re: Exceptions performance penalty

              Michael Andersson <a98mican@ida.h is.se> wrote in message news:<JR65b.266 67$dP1.68806@ne wsc.telia.net>. ..[color=blue]
              > Hi!
              > Does the use of exception handling induce a performance penalty during
              > the execution of non exception handling code?
              >
              > Regards,
              > /Michael[/color]

              See similar thread on news:comp.lang. c++.moderated :


              =============== =============== =======
              Alex Vinokur
              mailto:alexvn@c onnect.to

              =============== =============== =======

              Comment

              • Oliver S.

                #8
                Re: Exceptions performance penalty

                > AFAIK, this is already done (in g++ at least).[color=blue]
                >
                > 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.[/color]

                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.

                Comment

                Working...