From: Stefan Matthias Aust Date: 2001-05-26T18:10:05+09:00 Subject: [ruby-talk:15747] Re: java based interpreter and regexes Sean Russell wrote: >I wrote a little benchmark to test Ruby vs. org.apache.regexp. I compared Ruby 1.6.4 against JDK 1.4 beta and cannot confirm your results. (1.4 includes a regex package which looks like the one from the jakarata project so I used the built-in version) My ruby code needs some 4.7s to run (I used cygwin's time command) My java code needs some 2.7s to run (again measured with time) However, the time command also includes the time needed to initialize and start the VM, so I added code just to benchmark the 10000 RE-calls. Then, the ruby code still needs 4.3s but the Java code only 1.9s. So don't worry about the speed of the regexp code. I also doubt that this would be the most difficult part for a Ruby interpreter written in Java. To get it compatible with all "features" of the C one is much more challenging IMHO. >So Ruby is about 2.5 times faster. Not suprising, considering that regular >expressions in Ruby are handled by native code. I don't think the Java lib >is too slow. JIT-compiled code is typically faster than you'd expect. I don't want to go into details, but a sophisticated compiler like the SELF VM which was the precursor of the Hotspot VM is able to generate faster code than a static compiler can because its ability to dynamically recompile code based on type heuristics generated while the program is running. bye PS: Here's what I changed: ... import java.util.regex.*; ... Pattern regexpr = Pattern.compile(_re[regnum]); ... regexpr.matcher( _str[strnum] ).matches(); ... -- Stefan Matthias Aust \/ Truth Until Paradox