aspose file tools
The moose likes Java in General and the fly likes Pattern.compile and performance Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Pattern.compile and performance" Watch "Pattern.compile and performance" New topic
Author

Pattern.compile and performance

jeroen dijkmeijer
Ranch Hand

Joined: Sep 26, 2003
Posts: 131
Hi all,

I'm doing some string checking on various different columns in lines. A lot of these columns may have only alphanumeric characters with a min/max width of n.

Question: Is Pattern.compile internally caching its generated Patterns by some sort of FlyByWeight pattern or should I store them myself in a Map?
thanks in advance and regards,
Jeroen.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24081
    
  15

You should store them yourself -- unless, of course, the possibility of one being reused is not large enough to warrant the space.


[Jess in Action][AskingGoodQuestions]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18670
For what it's worth though, the Scanner class (JDK 5+) does cache the patterns it uses.

Also, bear in mind that there's an excellent chance that the time required to create and GC these Patterns may be insignificant relative to other things in your code. So like most performance concerns, it's probably best to not spend much time on it unless or until you've got an observable performance problem.


"I'm not back." - Bill Harding, Twister
jeroen dijkmeijer
Ranch Hand

Joined: Sep 26, 2003
Posts: 131
Once again thank you for your adequate and quick responses. Very helpful!
Jeroen.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Pattern.compile and performance
 
Similar Threads
problem in setting the column width of JTable
JTable column width problem..
JTable not occupying full scroll pane size - Scrollbar issue
Help with regular expressions
In java pattern matching how do declare string