From: "Ara.T.Howard" Date: 2005-09-03T00:21:25+09:00 Subject: Re: Ruby-specific performance heuristics? On Sat, 3 Sep 2005, Robert Klemme wrote: >> here's some things i think of: > > > >> - anchor every single regular expression : performance degrades >> exponentially otherwise > > That's not possible - especially with String#scan. Sometimes you want all > occurrences of something. true. however there nearly always __some__ anchor one can use: harp:~ > irb irb(main):001:0> "foo bar".scan %r/ \b\w+ /x => ["foo", "bar"] a better thing would be to say "use an anchor unless you know exactly why you shouldn't." >> - compile regular expressions only once unless they require >> variable substitution > > I guess you're talking about flag /o or storage of a regexp object somewhere > which is really only needed if the regexp contains interpolation that you > want to do only once. Otherwise a regexp *is* compiled only once and inline > regexps are roughly as performant as a stored regexp and might be easier to > read (not always). you are quite right - guy pointed this out to me once before - for some reason my brain hasn't retained it though ;-) cheers. -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | Your life dwells amoung the causes of death | Like a lamp standing in a strong breeze. --Nagarjuna ===============================================================================