From: Eric Young Date: 2006-03-12T15:58:43+09:00 Subject: Re: Help me understand why the Ruby block is slower than wit Benjohn Barnes wrote: > > On 11 Mar 2006, at 02:13, George Ogata wrote: > >> Another speedup: replace: >> >> w.split(//).uniq.size == 11 >> >> with: >> >> w !~ /(.).*\1/ > > !? :) How on earth does that work? Every time I think I've sort of got > the hang of regexp, they spring something new on me. > > I was also going to ask why everyone was doing "split( // )" instead of > "split( '' )"? > > - oooh, coffee's ready... > > Cheers, > Benjohn I was going to ask why everyone is not doing w.unpack("C*").uniq! == nil which seems faster than split(//) but slower than /(.).*\1/ 3.2s puts l if l !~ /(.).*\1/ 3.6s puts l unless l.unpack("C*").uniq! 7.3s puts l if l.split(//).uniq.size == 11 perhaps I deal with C code to much, but unpack seems a better String -> array mechanism. eric (rather new to ruby) *** Free account sponsored by SecureIX.com *** *** Encrypt your Internet usage with a free VPN account from http://www.SecureIX.com ***