On 3/19/08, James Tucker <jftucker / gmail.com> wrote:
>
>  On 18 Mar 2008, at 05:40, Gerardo Santana G=F3mez Garrido wrote:
>
>  > On Mon, Mar 17, 2008 at 6:08 PM, Paul Brannan <pbrannan / atdesk.com>
>  > wrote:
>  >>
>  >> On Tue, Mar 18, 2008 at 02:17:22AM +0900, Gerardo Santana G?mez
>  >> Garrido wrote:
>  >>> On Mon, Mar 17, 2008 at 12:42 PM, Marc Heiler <shevegen / linuxmail.or=
g
>  >>> > wrote:
>  >>>> Anyone of you has a few hints on how to speed up ruby code?
>  >>>> (Note - not writing it, but running it ;-) )
>  >>>>
>  >>>> I only have a few hints, like 5... would love to extend it.
>  >>>
>  >>> When generating text output, using StringIO is faster than using
>  >>> puts
>  >>
>  >> This doesn't make sense.  One can easily call #puts on a StringIO
>  >> object.
>  >>
>  >> Do you have a concrete example/benchmark that demonstrates the
>  >> difference?
>  >>
>  >> Paul
>  >>
>  >>
>  >>
>  >
>  > $ time ruby a.rb 10_000_000 > /tmp/a && sleep 3 && time ruby b.rb
>  > 10_000_000 > /tmp/b; printf "\a"
>  >
>  > real    1m45.305s
>  > user    1m27.581s
>  > sys     0m17.715s
>  >
>  > real    0m59.049s
>  > user    0m41.984s
>  > sys     0m16.997s
>  > $ cat a.rb
>  > times =3D ARGV[0].to_i
>  > times.times { puts "hola mundo" }
>  > $ cat b.rb
>  > require 'stringio'
>  >
>  > times =3D ARGV[0].to_i
>  > output =3D StringIO.new
>  > times.times { output.write("hola mundo\n") }
>  > output.rewind
>  > print output.read
>  >
>  >
>  > The difference increases in real world reports.
>  > --
>  > Gerardo Santana
>  >
>
>
>
> Do you not realize that this is fundamentally telling you your
>  terminal is super-slow?
> This has nothing to do with ruby itself,
>  really. Try it on some other platforms and tool stacks, for goodness
>  sake.


For goodness sake, read before replying. I'm not using any terminal.



>
>  Oh, and this is only really true for short strings and relatively
>  small amounts of memory. Try doing that whilst say, stream editing a
>  1TB file.

As I already said, this has proven true in real world reports.

>
>  This whole direction of thought is broken, honestly.
>

Fine. Don't take the hint.

--=20
Gerardo Santana