------art_140943_10345210.1167819866871
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On 1/3/07, Trans <transfire / gmail.com> wrote:
>
>
> Ryan Davis wrote:
> > On Jan 1, 2007, at 8:40 AM, Trans wrote:
> >
> > > I wonder how this would fair.
> > >
> > >   class Array
> > >     alias :old_join :join
> > >     def join( sep, last_sepl )
> > >       s  ld_join(sep)
> > >       if last_sep
> > >         rsep  egexp.escape(sep.to_s)
> > >         rlast  egexp.escape(last.to_s)
> > >         s.sub!(/#{rsep}#{rlast}$/,"#{last_sep}#{last}")
> > >       end
> > >       return s
> > >     end
> > >   end
> > >
> > > Sorry, the bencmark script wasn't posted and I didn't feel like
> > > recreating it.
> >
> > % ./blah.rb 1_000_000
> > # of iterations  000000
> >                            user     system      total        real
> > null_time             0.140000   0.000000   0.140000 (  0.139480)
> > ryan                 19.760000   0.020000  19.780000 ( 19.810269)
> > trans                21.290000   0.040000  21.330000 ( 21.398592)
> > Loaded suite ./blah
> > Started
> > ....
> > Finished in 0.001109 seconds.
> >
> > 4 tests, 24 assertions, 0 failures, 0 errors
>
> Eek. That was worse then I thought it would be. Thanks for showing me
> though, Ryan.
>
> Of course now that I'm looking at it again I'm wondering how we missed:
>
>   class Array
>     def join( sep, last_sepl )
>       return old_join(sep) unless last_sep
>       [slice(0...-1).old_join(sep), last].old_join(last_sep)


slice(0..-2).old_join(sep) << last_sep << last.to_s
or maybe
"#{slice(0..-2).old_join(sep)}#{last_sep}#{last}"

I like your approach of using old_join again, it seems so abstraction based,
but as we are looking for performance ;)

    end
>   end
>
> That must to be faster.
>
> T.
>
>
>
Robert

-- 
"The real romance is out ahead and yet to come. The computer revolution
hasn't started yet. Don't be misled by the enormous flow of money into bad
defacto standards for unsophisticated buyers using poor adaptations of
incomplete ideas."

- Alan Kay

------art_140943_10345210.1167819866871--