From: Michael Neumann Date: 2004-08-03T18:15:12+09:00 Subject: Re: performance stats of String#scan, strscan and a homemade approach Simon Strandgaard wrote: > because I recently have messed around with a ruby syntax colorer, > I needed to know more about the performance of #scan or if there > were faster alternatives.. String#scan seems to be the fastest. > > maybe this come others in handy. > > -- > Simon Strandgaard > > > bash-2.05b$ ruby h.rb > user system total real > String#scan 0.810000 0.020000 0.830000 ( 0.937981) > strscan 1.110000 0.040000 1.150000 ( 1.255724) > homemade slicer 2.420000 0.130000 2.550000 ( 2.648530) > true > true > bash-2.05b$ expand -t2 h.rb > require 'strscan' > def strscan(string, re) > tokens = [] > ss = StringScanner.new(string) > until ss.eos? > m = ss.scan(re) There's no advantage in your case when using strscan. Try to store the positions of the tokens and not the scanned string itself (the token) => StringScanner#skip. But that might not work for you. Regards, Michael