From: Kornelius Kalnbach Date: 2010-01-05T14:26:13+09:00 Subject: Re: Is ruby's regex slower? Roger Pack wrote: >> So perl is 7 or 8 times faster here. > You could try ruby 1.9 and see if it helps the speed. not very. I get best results in Ruby with: regexp = %r{href="http://([^"/]*)/[^"]*"\s+target="_blank"} 1000.times do puts File.read('index.html').scan(regexp) end ~/ruby/bench time ruby19 regex.rb > /dev/null real 0m1.428s user 0m1.359s sys 0m0.056s ~/ruby/bench time perl5.10.0 regex.pl > /dev/null real 0m1.189s user 0m1.095s sys 0m0.084s It's still slower. Perl has regular expression magic beyond my imagination, though. I heard they take the most "rare" character in the literal part of the regex (let's say, the colon) and search for it using machine code, and then work their way backwards to the beginning of the regexp... Say what you want, but Perl rocks when it comes to text processing speed. Python is even faster: import re regexp = re.compile(r'href="http://([^"/]*)/[^"]*"\s+target="_blank"') for i in xrange(1000): with open("index.html") as f: for m in regexp.finditer(f.read()): print m.group(1) time python2.6 regex.py > /dev/null real 0m0.943s user 0m0.880s sys 0m0.053s -- Posted via http://www.ruby-forum.com/.