I have run a little perf test.

My TryParse uses Double.TryParse and then Convert.ToInt32.

I get the following results:

When parsing valid data the TryParse method is 50% slower than
int.Parse. This difference is expected, it may even be rather less than
anticipated.
When parsing invalid data the int.Parse (throwing exceptions) is 90
times slower than TryParse!

I think I will change the code to use TryParse.

Nicko

> -----Original Message-----
> From: Mike Blake-Knox [mailto:[EMAIL PROTECTED] 
> Sent: 07 February 2005 21:57
> To: Log4NET User
> Subject: Re: Another exception in RollingFileAppender
> 
> On Mon, 7 Feb 2005 21:21:54 -0000, Nicko Cadell 
> <[EMAIL PROTECTED]> wrote:
> > The practice of throwing exceptions for expected conditions 
> is frowned 
> > upon as it can introduce severe performance penalties. 
> Microsoft are 
> > adding TryParse and IsNumeric calls to all the number types in .NET 
> > 2.0, however that is not a workable solution for us at the moment.
> 
> Understand. Error handling is always at least a bit of a challenge. 
> 
> --
> Mike Blake-Knox
> 

Reply via email to