On Thu, May 12, 2011 at 5:07 PM, Yoann M. <yoann6 / gmail.com> wrote:
> You're right, doing the buffer myself does not make it faster. For
> writing 10 millions lines, with an array of strings, one string, and no
> homemade-buffer (code is attached) :
> Buffer array : 11.141s
> Buffer string : 9.748s
> No buffer : 10.344s
>
> Don't you think using more RAM before writing on disk could make the
> process faster ? I thought so, then I'd like to say to File how much RAM
> it can uses to speed things up, because I can use a lot of RAM.

No, more does not help more.  With modern operating systems you never
directly write through to the disk.*  The OS is buffering your writes
anyway.  Even worse: using up much memory in the process to hold the
whole file can make your program slower because of the overhead of
memory allocation.  In the worst case your program is paged to disk.
Don't worry too much about this.

* Note there are some circumstances where you write directly to disk
(or rather, the write operation returns only after the disk
acknowledged the data).  This is sometimes called "direct IO".  This
does make sense in special circumstances only (some RDBMS can do it).

> Attachments:
> http://www.ruby-forum.com/attachment/6191/test_write.rb

You can make your life easier by using Benchmark for this.

require 'benchmark'

Benchmark.bm 20 do |x|
  x.report "a test" do
    ...
  end

  x.report "another test" do
    ..
  end
end

Kind regards

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/