amit punekar wrote:Hi James,
Thanks a lot.
Can you please help me understand it or point to the documentation that I can refer to ?
I have gone through various regex mentioned in the Java documentation but could not understand.
Thanks once again,
Amit
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Prime wrote:On my system, split1 is easily 10 times faster than split2. That's because with split2, using String.split, you create a java.util.regex.Pattern and java.util.regex.Matcher object each single time. It uses a List<String> to store the intermediate results (using Stirng.substring to create new String objects), then converts that List<String> into a String[].
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
James Sabre wrote:So what happens to your benchmark result if you pre-compile the regex?
And what happens if you perform make sure that the JIT has done it's job before doing the timing?
"premature optimisation etc etc etc".
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Prime wrote:
James Sabre wrote:So what happens to your benchmark result if you pre-compile the regex?
Using Pattern.split takes off about 33% of the time but it's still 8 times slower.
And what happens if you perform make sure that the JIT has done it's job before doing the timing?
How would I do that? I've just re-ran the tests with the same long loops after the first loops, so that's 10 million iterations after already having run 10 million iterations, and the results are similar.
"premature optimisation etc etc etc".
I agree but if I can replace using a regex with two simple loops (one for toCharArray internally, one for the copying) I'll definitely do that.
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
James Sabre wrote:
Still not good but "premature optimisation etc etc etc".
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Ireneusz Kordal wrote:
James Sabre wrote:
Still not good but "premature optimisation etc etc etc".
Imagine how long it will take to understand a magic formula (?!^) by someone who will maintain your code in the future
and some day will must quickly fix a serious bug but will not be an expert in regular expressions.
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
James Sabre wrote:That is a simple regular expression so this does not wash as an argument. Using your argument one would never ever ever use anything except the most trival algorithms. One would use crude DFT rather than FFT. One would use brute force rather than Dijkstra when looking for shortest paths. One would use simple linear search rather than KMP.
I expect programmers to understand basic tools and I regard regex as a basic tool.
James Sabre wrote:I regard regex as a basic tool.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Prime wrote:
James Sabre wrote:I regard regex as a basic tool.
I think that's where we disagree on most. Regexes are very useful, true, but definitely not "basic". I've bought and read "Mastering Regular Expressions" and its writers too agree that regular expressions are far from a simple topic. There's a reason there are many books on regexes.
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
James Sabre wrote:Is counting published books on a topic a good metric for the complexity of a topic?
This is turning into a religious argument so I will bow out now.
Mike Simmons wrote:Mmm, I'm not following you there David. Why would the first entry be skipped?
It works but with a small hitch, the first String in the array is EMPTY String.
Regards,
Amit
Don't get me started about those stupid light bulbs. |