Skip to content.

Manageability

Sections
Personal tools
You are here: Home » blog » archive » Incorrect use of regex

Comment

Above in this comment thread: The Ultimate Java Versus C# Benchmark

Incorrect use of regex

Posted by Anonymous User at 2006-04-09 03:50 AM

As already pointed out, it is no good to run the C# with the RegEx Option RegexOption.Compile on. When run with no options on, the C# runs and finished in 8890 ms. Additionaly, I replaced the switch in convert with a string[] => { "A","G","T","C"}, this way we actually can access these directly instead of using a switch.

The Java version finished in 5031 ms. (standard J2SE 5.0) With the switch replaced with an array, it finishes in 4391ms.

So what does that tell me? 1. The above C# code is poorly written. 2. Java is about twice as fast as C#.

So, go java! =D

Same thing.

Posted by Anonymous User Anonymous User at 2006-04-14 07:05 AM

Well, I agree with the above commentators, in that the above C# code is crappy. But, we really can't blame you, since It looks like you're basically a Java Coder. Heck, I'd write crappy Java code if I was asked to. And, with just the Regex error corrected, the C# code finishes at 18secs, which is about twice the time taken by Java. So, it's a 2x Difference, not a 7,733x difference:D

And, BTW, when the hell did DNA Sequencing become a "REAL LIFE" thing ?

Perhaps im missing the point...

Posted by Anonymous User Anonymous User at 2006-04-23 03:36 PM

However if you are doing a straight up Text Sequence Match ( which is what the example code is doing ) then you would use the .IndexOf method off the string object.

Of Course Im probably missing the point.. but you used the term Real World up there...

In Main, make the following change...

Comment : Regex regexpr = new Regex(matchthis.ToString(), RegexOptions.Compiled);

Comment : Boolean b = regexpr.IsMatch(_doc);

Replace : if (B) with : if ( _doc.IndexOf( matchthis.ToString()) > -1 )

When reRun, with no other changes, causes an end number of approximately ".NET regex took 1687 miliseconds"

Would be interested in seeing the Java equivalent change + perf. With the understanding that a implementation .IndexOf Java equivalent will probably be significantly different then .net

.Net version was 1.1

 
 

Powered by Plone

This site conforms to the following standards: