It's not a secret anymore!
The moose likes Performance and the fly likes is matches() slower than the char array check in String validation? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "is matches() slower than the char array check in String validation?" Watch "is matches() slower than the char array check in String validation?" New topic
Author

is matches() slower than the char array check in String validation?

Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 271

is this slower ???


than this ???



Time is what we want the most, but what we use the worst. -- William Penn
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 862
1) I suspect this would never be a bottleneck in a real application so it makes more sense to do which makes your vailidation the most flexible and easiest to maintain. Either way I would come up with a validate(...) method and hide the implementation.
2) If you really want to see performance differences run a lot of validations and time each approach.
3) You can also look at the source code. Here is a good site that has the java source. String.matches calls Pattern.matches. http://www.java2s.com/Open-Source/Java-Document/6.0-JDK-Core/Collections-Jar-Zip-Logging-regex/java/util/regex/Pattern.java.htm


http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4659
    
    5

Robin John wrote:


Does your code work internationally? Its probably fine for ASCII, but the A in ASCII is American.

A major point of the generalized pattern stuff is to fit well into international code, I tend to think that languages such as Arabic or Tamil are not going to use American digits.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: is matches() slower than the char array check in String validation?
 
jQuery in Action, 3rd edition