473,466 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

What's the Cost of a Try Block


We are building a high performance system and suddenly the cost of
using exception has been magnified.

What is the actual cost of having a frequent call inside a try-catch
block when the vast majority of times there will be no exception to
catch?

Many thanks.

Jan 19 '07 #1
5 7447

Tiglath wrote:
We are building a high performance system and suddenly the cost of
using exception has been magnified.

What is the actual cost of having a frequent call inside a try-catch
block when the vast majority of times there will be no exception to
catch?
I would think that someone experienced in building high performance
systems would know how to use a profiler...go figure.

It's implementation dependent. Could be nothing...could be an increase
in size....could be an increase in time...

You'll just have to use the scientific method.

Jan 19 '07 #2

Tiglath wrote:
We are building a high performance system and suddenly the cost of
using exception has been magnified.

What is the actual cost of having a frequent call inside a try-catch
block when the vast majority of times there will be no exception to
catch?

Many thanks.
Scott Meyers, "More Effective C++" has a good analysis on this, you
should read it.. but the gist is there will be an overhead associated
with exceptions, however if you do not incurr exceptions often (which
should be the case!), you probably will only take about a 5% hit in
performance... He cites studies in his book, I don't have it handy for
reference, sorry. But, thumb through it, its a pretty good book.

Jan 19 '07 #3
bjeremy wrote:
>
Scott Meyers, "More Effective C++" has a good analysis on this, you
should read it.. but the gist is there will be an overhead associated
with exceptions, however if you do not incurr exceptions often (which
should be the case!), you probably will only take about a 5% hit in
performance... He cites studies in his book, I don't have it handy for
reference, sorry. But, thumb through it, its a pretty good book.
Be sure to check out which compilers he's talking about. Compilers for
Windows used to use SEH for exceptions, and that, indeed, added runtime
overhead. Newer compilers are getting away from that, since it's not
really appropriate. And compilers for other platforms never did it.
Hypothetically, exceptions can be implemented with no runtime overhead
if you don't throw exceptions (except possibly for lost optimization
opportunities), and some compilers do just that.

As ever, the answer is, measure it.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
Jan 19 '07 #4
Tiglath wrote:
We are building a high performance system and suddenly the cost of
using exception has been magnified.

What is the actual cost of having a frequent call inside a try-catch
block when the vast majority of times there will be no exception to
catch?
If you do not use exceptions as return value for one of correct state,
you will have no overhead if no error condition will occur.

This is one of example:

//code without exceptions
movl %esp, %ebp
pushl %ecx
subl $20, %esp
call _test
leave
ret

//the same code with exceptions
movl %esp, %ebp
pushl %ecx
subl $20, %esp
call _test
jmp L28
//catch
call ___cxa_begin_catch
call ___cxa_end_catch
L28:
leave
ret

if no error condition will occur, program with exception will be longer
by one "jump" opcode. Of course, size of program with exception will be
greater, than without, but you can not make size smaller even with
manual control:

if(error_condition){print_error(); return;}
do_any();

will always ne longer then just

do_any();

Compiler even can tell CPU what kind of jump condition has more
priority for anticipatory memory access, if CPU supports it.

Jan 20 '07 #5

Tiglath skrev:
We are building a high performance system and suddenly the cost of
using exception has been magnified.
How? Did you measure the performance or is it just something you
believe is so?
>
What is the actual cost of having a frequent call inside a try-catch
block when the vast majority of times there will be no exception to
catch?
I don't believe there will be any overhead at all, but I'd question
your design anyway. Why do you need a try-catch around a function that
you believe is a bottleneck? In my experience, proper C++ code has very
few try-catch blocks, and they are never at such low a level.

/Peter

Jan 20 '07 #6

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

Similar topics

28
by: David MacQuigg | last post by:
I'm concerned that with all the focus on obj$func binding, &closures, and other not-so-pretty details of Prothon, that we are missing what is really good - the simplification of classes. There are...
8
by: Danny | last post by:
Hi Could somone please criticise the following program, it went together far to easily (bearing in mind i am just getting into c++) **note the tabs are not as they appear in my compliler** ...
10
by: Steven T. Hatton | last post by:
I read Stroustrup's article of the day: http://www.research.att.com/~bs/C++.html Programming with Exceptions. InformIt.com. April 2001. http://www.research.att.com/~bs/eh_brief.pdf Some of...
13
by: gtux | last post by:
Hi everybody: I'm new in Javascript, I found some code and there is this: var fruit = { 'apple' : { 'weight' : 10, 'cost' : 9}, 'peach' : { 'weight' : 19, 'cost' : 10} }
96
by: BadPony | last post by:
Anyone using Peoplesoft on a Federated UDB (shared nothing)Environment on Open System Platforms? Preferably AIX, but any war stories would be good. TEA EB-C
41
by: Matt Alanzo | last post by:
Our SOHO 2 person compay sells furniture (not programmers). In '98 we paid $,$$$ for a VBA -Access '97 accounting application, including VBA source code .... an huge investment for us then (and...
140
by: Oliver Brausch | last post by:
Hello, have you ever heard about this MS-visual c compiler bug? look at the small prog: static int x=0; int bit32() { return ++x; }
14
by: Salad | last post by:
On the computer side of the businees there is me, the developer. Another person's role is that of the idea man...the person that knows the business and requirements and issues for the business. ...
7
by: walter.alex | last post by:
November 16 2005 -- The recent launch of the new 5 year advertising solution from MillionPixelClick.com means the pixel advertising craze will continue unabated. Selling advertising space by the...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.