Re: Slow performance after Conversion C# application to VS 2005

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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.

.



Relevant Pages

  • Re: remove double space from string
    ... 293 milliseconds ... but that's a simple matter to add, what i'm really timing is if the loop ... yep that favors the regex version...the more spaces the better regex ... // another regex option: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Stupid Mistakes
    ... before the loop. ... ...oh, I see, it's a global set by findswfile. ... when you come back to this in six months' time) some searching. ... is a special character in a regex, ...
    (comp.lang.perl.misc)
  • Re: TaskSpeed results for My Library
    ... But what is this apparent function declaration doing here (in this ... of syntax extension that accommodate apparent function declarations in ... This is the main timing loop. ... Date object is more than 200 milliseconds after the date reported by ...
    (comp.lang.javascript)
  • RE: Reading contents of file
    ... keep the regex match as it is i.e. while ... But inside the loop when you a find a match and do relevant things, ... the existence of the matched pattern which is done by the help of bookref ... When I run the following script it goes to unending because it is ...
    (perl.beginners)
  • RE: Reading contents of file
    ... 2)I am not able to print the unmatched data i.e in the above example '45' doesn't match the regex in the while loop so this cannot be printed in the output file. ... the existence of the matched pattern which is done by the help of bookref ...
    (perl.beginners)