This means that patterns are almost 3.5 times slower. Therefore although regular expressions provide very convenient way for searching within strings sometimes when pattern are very simple and code is very performance critical we should use the good old methods provided by class java.lang.String.
With that I have to say that I paid attention that method indexOf() accepts String, method contains() accepts CharSequence but is implemented as
return indexOf(s.toString())>=0.
Pattern at the same time works directly with CharSequence. This means that if you use StringBuilder you should be careful passing StringBuilder instance as an argument to String methods: creating new String object may cause significant performance degradation.
No comments:
Post a Comment