Re: Real life cost of using exceptions for control flow?
From: Jerry Pisk (jerryiii_at_hotmail.com)
Date: 06/11/04
- Next message: Jeroen Pot: "Copy large dataset"
- Previous message: Jon Skeet [C# MVP]: "Re: Real life cost of using exceptions for control flow?"
- In reply to: Jon Skeet [C# MVP]: "Re: Real life cost of using exceptions for control flow?"
- Next in thread: Alvin Bruney [MVP]: "Re: Real life cost of using exceptions for control flow?"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 11 Jun 2004 13:28:37 -0700
I agree, that if we're talking about throwing several hundreds of exceptions
an hour there's no performance issue. However, exceptions are very expensive
compared to value checks (i.e. the cost of Param == null is pretty close to
zero compared to throwing an exception) so if you're writing performance
critical code (such as drawing code mentioned by Frank, or web application)
you should avoid exceptions at any cost. And you need to realize that ANY
web application is performance critical, since poor performance can very
easily lead to DoS on even the least used server.
And if I had to generalize I would say the threshold would be somewhere
around 1,000 exceptions a second, not hundreds (or even tens) of thousands.
Jerry
"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.1b3369db8d796a2198abf6@msnews.microsoft.com...
> Jerry Pisk <jerryiii@hotmail.com> wrote:
>> Jon, could you please post the code that throws and catches hundreds of
>> thousands exceptions per second? My box (dual PIII @ 850) can only run
>> about
>> 35,000 to 40,000 of the following in a second:
>>
>> try
>> {
>> throw new ApplicationException("Just testing.");
>> }
>> catch(Exception)
>> {
>> }
>>
>> I would like to see code that can throw and catch exceptions ten times as
>> fast.
>
> using System;
>
> public class Test
> {
> static void Main()
> {
> DateTime start = DateTime.Now;
> for (int i=0; i < 1000000; i++)
> {
> try
> {
> throw new Exception();
> }
> catch
> {
> }
> }
> DateTime end = DateTime.Now;
> Console.WriteLine (end-start);
> }
> }
>
> That's a million exceptions, and on my laptop (P4/3GHz) it takes 9.25
> seconds. So maybe "hundreds of thousands" should have been "over a
> hundred thousand" - but it's still enough that 200 per hour isn't going
> to be an issue :)
>
> --
> Jon Skeet - <skeet@pobox.com>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too
- Next message: Jeroen Pot: "Copy large dataset"
- Previous message: Jon Skeet [C# MVP]: "Re: Real life cost of using exceptions for control flow?"
- In reply to: Jon Skeet [C# MVP]: "Re: Real life cost of using exceptions for control flow?"
- Next in thread: Alvin Bruney [MVP]: "Re: Real life cost of using exceptions for control flow?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|