RE: Check value is number only
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Fri, 15 Jul 2005 17:25:18 +0100
Brendan Grant <grantb@xxxxxxxxxxxxxxx> wrote:
> Code readability is always good, however there are times when performance is
> more important than readability, and with extensive testing one can
> dramatically reduce the risk of such a complicated regular expression from
> causing you issues.
>
> While using a Parse() may be simpler and more readable, I disagree that it
> is more efficient.
I don't think you read my post properly. I wasn't suggesting *just*
using int.Parse - I was suggesting a simple method to test for just
digits (without using a regular expression) followed by a call to
Parse.
> Usage of either depends on which side you want to pay the
> penalty of an unparseable value.
>
> If it is a parseable value being passed in, then yes, Parse() faster, an
> order of magnitude faster in the best case. On the other hand, if a lot of
> invalid values are being dealt with, using the Regex method can be in the
> best case ~50 times faster than Parse().
Whereas a hard-coded test followed by int.Parse can be about 50x faster
than Regex.
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.
- References:
- Check value is number only
- From: Mike L
- RE: Check value is number only
- From: Brendan Grant
- RE: Check value is number only
- From: Jon Skeet [C# MVP]
- RE: Check value is number only
- From: Brendan Grant
- Check value is number only
- Prev by Date: Re: noob question: how do i access the object sender properties
- Next by Date: Re: Loading String into FileStream
- Previous by thread: RE: Check value is number only
- Next by thread: Loading String into FileStream
- Index(es):
Relevant Pages
|