Re: Slow performance after Conversion C# application to VS 2005
- From: "Jack" <cd_le@xxxxxxxxxxx>
- Date: 29 Mar 2006 10:17:15 -0800
Well, I thought there might have been an overall problem with 2.0
performance. But I think I have to look at certain aspects. My
application is processing a lot of input data we get in XML. In the
part where all data is read into memory and stored in some variables
there's a routine called ValidateRecords. Basically a lot of checks are
done here like all kinds of string compares and regular expressions. I
didn't write this code myself so I didn't know what to think of
earlier.
Now I have looked at that part nore specific and I have tested all
kinds of stuff. In general I have looked at Array.Sort and
string.Compare which cause slower performance on .Net Framework 2.0.
But those are not my problems. Currently I just achieved to define a
test which shows I do have a problem with Regular Expressions in .Net
Framework 2.0.
This is my testcode:
int testNumber = 1000;
MatchCollection matches;
for (int i = 0; i < testNumber; i++)
{
Regex RegexWord = new Regex(@"\b(\d+[\.,](\d+|-)|\w+)\b",
RegexOptions.IgnoreCase |
RegexOptions.Compiled);
matches = RegexWord.Matches("njdjjd"); // GetDuur(oRegexWord);
int count = matches.Count;
}
On .Net 1.1 this loop takes 16 milliseconds, while on .Net 2.0 this is
like 7500 milliseconds.
If I take the Regex variable declaration and instantiation out of the
loop it only takes 300 millseconds.
If I leave it in the loop but don't assign count by commenting the last
line it also takes around 300 milliseconds. Why is the combo of these 2
within the loop taking so long?
And I did take these lines from some object somebody made and these 3
lines are processed for every record.
The Regex declaration is in the constructor of the object and it's
always the same, so is making it static my solution (Don't really
understand Regex enough to know whether it is safe for me) or is there
a better one? A better one would be an alternative where I can achieve
the 15 milliseconds, so we are not losing time (20 times longer) if we
use .Net 2.0.
I also want to understand why the 3 lines all together take so long and
why it goes fast if line 1 or 3 are out of the loop. So maybe somebody
can explain it to me? I saw in the code that there are a lot more Regex
used in several ways, so totally understanding what's wrong and how to
fix it can help me completely.
.
- Follow-Ups:
- References:
- Slow performance after Conversion C# application to VS 2005
- From: Jack
- Re: Slow performance after Conversion C# application to VS 2005
- From: Jon Skeet [C# MVP]
- Slow performance after Conversion C# application to VS 2005
- Prev by Date: Re: WebException
- Next by Date: Re: clr20r3 Error
- Previous by thread: Re: Slow performance after Conversion C# application to VS 2005
- Next by thread: Re: Slow performance after Conversion C# application to VS 2005
- Index(es):
Relevant Pages
|