From: Ryan Davis Date: 2012-02-03T08:20:15+09:00 Subject: Re: Basic Ruby performance On Feb 2, 2012, at 14:55 , Dmitry Nikiforov wrote: > Here's another example with significantly bigger performance difference: > > Ruby: > > s = "This is a test string" > > re = Regexp.new( / test / ) > > for a in 0..1E7 > re.match( s ) > end > > Perl: > > my $s = "This is a test string"; > > for my $a ( 0..1E7 ) { > $s =~ / test /; > } > > Perl takes about 1.5 seconds to execute this, while Ruby takes a > whopping 16!!! :((( I have a very strong feeling that I didn't compile > Ruby properly - there can't be such a huge difference in regexp matching > :( It's all the parens, whitespace, and use of tabs that slows ruby down: # takes 26.6 seconds on my laptop: s = "This is a test string" re = Regexp.new( / test / ) for a in 0..1E7 re.match( s ) end # takes 8.67 seconds on my laptop: s = "This is a test string" for a in 0..1E7 s =~ / test / end