From: Robert Klemme Date: 2003-04-11T02:25:48+09:00 Subject: Re: Need IO Optimization help "Jim Freeze" schrieb im Newsbeitrag news:20030410124342.A7291@freeze.org... > On Friday, 11 April 2003 at 1:27:25 +0900, nobu.nokada@softhome.net wrote: > > Hi, > > > > At Fri, 11 Apr 2003 01:03:08 +0900, > > Jim Freeze wrote: > > > The Ruby code is below. I know there have been multiple > > > posts on ruby-talk about this with discussions about > > > sysread and read, but not being an IO expert, I have > > > only been able to follow these at a high level. > > > > You can use File.cp in ftools.rb or FileUtils.cp in > > fileutils.rb. > > > I see the syswrite src.sysread(bsize) in copy_stream, but > I need the data line by line to process. It's just that > for our tests we are not doing any processing. > So, while a direct copy may be fast, it is not exactly > what I want. > > def copy_stream( src, dest ) > bsize = fu_stream_blksize(src, dest) > begin > while true > dest.syswrite src.sysread(bsize) > end > rescue EOFError > end > end > > > Is there a system call that reads line by line? Not as far as I know. But you can simulate this with String#each by reading the whole file in one go and then iterating: contents = f.read() contents.each {|line| # processing... } or work directly on contents by using String#sub! Did you try to use "file.sync= false" in conjunction with "file.flush"? Did you try reading the whole file in with "contents = file.read()" and then do line by line processing by doing "contents.each { |line| .... }? And: did you make sure that IO is the problem and not the processing part? Regards robert