[posted & mailed]

On Feb 7, Kirk Haines said:

>Program A:
>
>  z = 0
>  t = "0123456789abcdefghijklmnopqrstuvwxyz"
>  (0..999999).each { z += 1 if t =~ /abc/ }
>
>Program B:
>
>  z = 0
>  t = "0123456789abcdefghijklmnopqrstuvwxyz"
>  rexp = Regexp.new('abc');
>  (0..999999).each { z += 1 if rexp.match t }
>
>B has a runtime that is about 1.7 times A.  Why?  This is on Ruby 1.6.6 on
>a Linux box.

I would guess it is because the builtin =~ operator works faster than the
creation of a Regexp object and subsequent method calls.  Regexp objects
are particularly useful when looping over a list of them.

-- 
Jeff "japhy" Pinyan      japhy / pobox.com      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.