473,414 Members | 1,667 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Exceptions performance penalty

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

Regards,
/Michael

Jul 19 '05 #1
7 9222
> 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.
Jul 19 '05 #2
> 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
Jul 19 '05 #3
"Peter van Merkerk" <me*****@deadspam.com> wrote in message news:<bj************@ID-133164.news.uni-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
Jul 19 '05 #4
> > > 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

Jul 19 '05 #5
ha*************@yahoo.com (Hafiz Abid Qadeer) wrote in message news:<9c**************************@posting.google. com>...
"Peter van Merkerk" <me*****@deadspam.com> wrote in message news:<bj************@ID-133164.news.uni-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
Jul 19 '05 #6
Michael Andersson <a9******@ida.his.se> wrote in message news:<JR*******************@newsc.telia.net>...
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
mailto:al****@connect.to
http://mathforum.org/library/view/10978.html
=====================================
Jul 19 '05 #7
> 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.
Jul 19 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

59
by: kk_oop | last post by:
Hi. I wanted to use exceptions to handle error conditions in my code. I think doing that is useful, as it helps to separate "go" paths from error paths. However, a coding guideline has been...
1
by: Peter Bär | last post by:
A Question to the C#/.Net Gods of this forum: are there performance penalties when i compile (C#, FW1.1, ASP.NET, Studio2003) a central baseclass in a different assembly than all the derived...
6
by: RepStat | last post by:
I've read that it is best not to use exceptions willy-nilly for stupid purposes as they can be a major performance hit if they are thrown. But is it a performance hit to use a try..catch..finally...
9
by: Alvin Bruney [MVP] | last post by:
Exceptions must not be used to control program flow. I intend to show that this statement is flawed. In some instances, exceptions may be used to control program flow in ways that can lead to...
2
by: Peter Bär | last post by:
A Question to the C#/.Net Gods of this forum: are there performance penalties when i compile (C#, FW1.1, ASP.NET, Studio2003) a central baseclass in a different assembly than all the derived...
18
by: Digital Puer | last post by:
Hi, I'm coming over from Java to C++, so please bear with me. In C++, is there a way for me to use exceptions to catch segmentation faults (e.g. when I access a location off the end of an array)?...
6
by: GiddyUpHorsey | last post by:
We have a website built on ASP.NET 2.0. We log exceptions in the Error event of Global.ASAX. We keep a getting number of random exceptions that make no sense and that we can't reproduce but happen...
40
by: Mark P | last post by:
I'm implementing an algorithm and the computational flow is a somewhat deep. That is, fcn A makes many calls to fcn B which makes many calls to fcn C, and so on. The return value of the outermost...
11
by: Paul H | last post by:
Suppose I have a table called tblPeople and I want a field to illustrate whether each person prefers cats or dogs. I could do it one of three ways. 1. A plain text field Create a text field in...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.