From: Josh Cheek Date: 2012-02-03T12:47:01+09:00 Subject: Re: Basic Ruby performance --f46d0442816a349e7904b8072a75 Content-Type: text/plain; charset=ISO-8859-1 On Thu, Feb 2, 2012 at 8:57 PM, Jeremy Bopp wrote: > > Try a similar change to the other looping variations that have been > discussed and see if and how much they may improve. For me I didn't > really see any difference between using re as above or using the simple > regexp directly; however, the code was almost an order of magnitude > slower when I replaced the comparison as follows: > > s =~ / test#{} / > > It seems that Ruby is smart enough to see that the simple regexp will > never need to be re-evaluated. The regexp used above must force that > optimization off because #{} while constantly evaluated to the empty > string is technically dynamic, thus the regexp needs to be re-evaluated > in every iteration of the loop. > > The o flag tells Ruby to only interpolate the first time, and then cache the regex s =~ / test#{} /o --f46d0442816a349e7904b8072a75--