[Tech]When a Tradeoff doesn't pay....
Well, I was just browsing around, and came across this blog post comparing Java performance to C# Performance.Though the post looks a bit old, It got some really funny and unfair Results. And, ofcourse, some People have already pointed out that and several other mistakes in the program. And then, there was a really, uhm, fun conclusion, concluding that Java was 7.733x faster than C#! Hmm... And, he also got an Out of Memory Exception. Since this kinda thing hasn't happened to me before, I just sorta looked at the code, and surprise surprise, something leaped out at me : He was instantiating a Regex class to be used only once, inside a Loop that repeated 1000000 times. Well, that's not the problem, since the Java version is doing the same thing, and getting pretty acceptable results[atleast so I think]. But the real Problem was, he was using the RegexOptions.Compiled option to compile the Regex to MSIL at Runtime.So, Basically, he's involving Reflection, Dynamic Code Generation and tons of other stuff without intending to do so. And, the result, as expected, will be Pathetic. So, I just removed that, compiled, and got a Performance boost of 7.331.3x, so now the C# version takes 18 secs to Complete, while the Java Version takes 9 to complete.
Moral of the Story : Don't use RegexOptions.Compiled if you're not going to use the same Regex object more than a 100 or even 1000 times. Though compiling decreases the matching time, It increases the object instantiation time considerably. So, don't blame C# if you're writing code like that.
P.S. I tried to compile the Java Version given there, and I even went out of my way to hunt up my languages CD and install JDK. Yeah, but then, I compile it using javac, and tried to run the
.class
file using java
. Yeah, but all I got was an Exception:
Exception in thread "main" java.lang.NoClassDefFoundError : rbenchSigh! So, can somebody who knows Java better than seeing 11th guys compile hello world apps using EDIT compile that code and tell me the results ? Thanks.... P.P.S: But, looks like I can't really blame that guy : He's a Java Guy, and maybe can write great Java apps, but not really good C# code. If you ask me to churn out some Java Code, I'd be just as[or more] crappy. P.P.P.S. : I just changed the Title again, because The RegexOptions.Compiled parameter tradesoff Initialization Time for faster Matching. In this case, the Tradeoff simply doesn't pay off...
1 Comments:
Excellent, love it!
credit card microsoft free spyware vardenafil hydrochloride the drug scholarship applications cash+las+loan+quick+vegas lekarstwo xanax generic viagra home insurance mortgage leads webster county auto insurance internet fax elementary education in the next 10 years canada from vicodin romantic hotels cannon beach oregon car insurance comparison
Post a Comment
<< Home