Re: Real life cost of using exceptions for control flow?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Frank Hileman (frankhil_at_no.spamming.prodigesoftware.com)
Date: 06/11/04


Date: Fri, 11 Jun 2004 09:24:01 -0700

This test cannot be generalized to all exception performance problems. We
found exceptions thrown by System.Drawing during a display pass caused such
a dramatic slow-down that we wrote elaborate code to avoid exceptions. It
could be that exceptions thrown by unmanaged code wrappers are unusually
slow. In general, the only way to determine the extent of the problem is to
test on your own code.

This is why the .NET design guidelines recommend avoiding exceptions for
expected or common error conditions. Throwing exceptions during drawing
operations, for example, should never be acceptable, since it causes so many
problems. For us, the difference was a smooth display, versus an unusable
display.

Regards,
Frank Hileman

check out VG.net: www.vgdotnet.com
Animated vector graphics system
Integrated Visual Studio .NET graphics editor

"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
news:eeVboc8TEHA.1036@TK2MSFTNGP09.phx.gbl...
> well this little thread for me was an eye opener. i was thinking
exceptions
> were expensive to the order of at least a second or so however the results
> prove otherwise. i guess the architects did a good job with the
> implementation of the exception mechanism.
>
> --
> Regards,
> Alvin Bruney
> [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
> Got tidbits? Get it here... http://tinyurl.com/27***
> "Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
> news:MPG.1b33d51660809a6f98ac0c@msnews.microsoft.com...
> > <"Alvin Bruney [MVP]" <vapor at steaming post office>> wrote:
> >> the design is already bent out of shape and wrong because exceptions
are
> >> used to control program flow.
> >
> > It's hard to say that for sure without seeing code. "Control program
> > flow" means different things to different people.
> >
> >> now, 005 milliseconds is the simple case. If
> >> you have code cleanup and deallocations in a catch block, you are
talking
> >> a
> >> lot more than 005 milliseconds.
> >
> > Note - not 005 milliseconds, 0.005 milliseconds. Big difference
> > (although when multiplied by 200 you'd still only get a second per hour
> > with a 5 millisecond penalty per exception).
> >
> >> That kind of time starts to become
> >> noticeable especially in a web app, when you have to factor the cost of
> >> rendering and data transmission.
> >>
> >> my personal philosophy has always been to refactor code constantly to
> >> keep
> >> it sharp and well tuned. after all, athletes train everyday but they
> >> don't
> >> compete everyday. they train to keep well oiled machines working at
peak.
> >> so
> >> why not tune software everyday if it runs everyday?
> >
> > If you have a lot of cleanup and deallocations in the catch block, then
> > chances are you'd have to do the same kind of cleanup without
> > exceptions - you'd just be doing it in a different place.
> >
> > Without considerably more detail it's hard to say for sure how much
> > performance impact those 200 exceptions per hour are making, but I
> > *very* much doubt that it's significant.
> >
> > --
> > Jon Skeet - <skeet@pobox.com>
> > http://www.pobox.com/~skeet
> > If replying to the group, please do not mail me too
>
>


Quantcast