From: Bertram Scharpf Date: 2005-01-10T12:32:03+09:00 Subject: Re: brute force string search Hi, Am Montag, 10. Jan 2005, 09:51:22 +0900 schrieb Martin Pirker: > given: String of several Mb > problem: find the lines in String containing "xyz" > > > Idea 1: > String.scan(/.*xyz.*/) -> ~10s runtime > > Idea 2: > String.grep(/.*xyz.*/) -> ~3s (but gives the \n too) > > Idea 3: > loop String.index("xyz",lastmatch+3) > loop results array and grep in match area for line > -> 0,5s > > C extension the only faster option left? :-) What about this: str = File.new( 'longfile').read str.scan /.*/ do |x| puts x if x =~ /xyz/ end Bertram -- Bertram Scharpf Stuttgart, Deutschland/Germany http://www.bertram-scharpf.de