• Post Reply Bookmark Topic Watch Topic
  • New Topic

Which is faster : Jakarta RegExp or Java RegExp?  RSS feed

 
Chandrakant Dhome
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Which is faster : Jakarta RegExp or Java RegExp?
What are other pros and cons for both?

-Chandrakant
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've no idea which is faster. I would guess, however, that any blanket statement that one is faster than the other is likely to be a useless over-generalisation. As both are written by good programmers, they are both likely to be generally efficient, but each may do some things faster than others.

Therefore, if you really need the ultimate performance, you should benchmark them against one another, for the sort of regular expressions you expect to encounter in your application.

Personally, I would always use the Java built-in regular expressions (java.util.regex.Pattern), until proven that I needed to do otherwise. After all, why add the bloat and complication of a third-party library to do something that Java can do already? For Java's regular expressions, you need to be using at least Java 1.4.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36441
454
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If performance is important, you need to tune the regular expression for the particular reg exp engine you are using. Different engines are implemented different ways as you would guess. This means that an equivalent reg exp may perform significantly faster than the first one you write.

The O'Reilly Regular Expression book goes into quite a bit of detail on this.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36441
454
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And I echo Peter's advice on starting with the Java library. I've used it for some time. There was only one reg exp that I couldn't tune to an acceptable level. I solved it by splitting the problem into two parts (using substring) and solving each one. Some of the more performance intensive ones involve reading a multi-megabyte string and searching for specific lines - over and over and over. It's just a utility (non-production code), but we do this so many times that each one needs to be fast. And we run it every day.

I did use Jakarta's library before we were on Java's for some smaller problems. I didn't notice any difference in performance.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're set on using a 3rd-party library, then in my opinion JRegex is the best one. It has a lot more options than Jakarta RegExp (e.g. Unicode support, lookahead, non-capturing parentheses etc.), and is faster than Jakarta ORO (which is also more feature-rich than Jakarta RegExp).

But as said above, java.util.regex is a strong contender.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36441
454
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't realize there were to Jakarta regular expression libraries. My comments above pertain to the ORO one.
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<<Personally, I would always use the Java built-in regular expressions (java.util.regex.Pattern), until proven that I needed to do otherwise. >>
Ditto.

If you want to compare performance use your own interface and wrap each of the 2 classes in yours. My guess is that in most applications the performance differences are smaller than other bottlenecks in your program.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!