From: Brian Mitchell Date: 2006-04-06T10:14:32+09:00 Subject: Re: compare to strings On 4/5/06, Dominik Bathon wrote: > So, regular expression matching itself is not that much slower than > String#include?. > What makes "url2 =~ /#{url}/" slow is the creation of so many Regexp > objects. Ruby has some very subtle optimizations for Regexps too: # ruby 1.8.4 (2006-03-20) [powerpc-darwin8.5.0] GC.disable n = ObjectSpace.each_object(Regexp){} def foo; /abc/ end # Note I didn't call foo. ObjectSpace.each_object(Regexp){} - n #=> 1 1000.times {foo} ObjectSpace.each_object(Regexp){} - n #=> 1 It is always nice to see simple optimizations like this. Brian.