From: Ron Jeffries Date: 2002-03-08T00:38:49+09:00 Subject: Re: file reading impossibly slow? On Thu, 07 Mar 2002 13:34:38 GMT, Peter Hickman wrote: >Your file reading is a bit non-ruby, so to speak, you need to get the >hang of itterators. Doubtless I do. But this is really going to be a binary file, read with read(). I just put the newlines in to make it easy. So this solution won't stick for the long run. Nobu tells me I should go to 1.7. Not sure if I'm up to that challenge, but it sounds pretty fast from his numbers. Unless he was running on a Cray or something. > >t1 = Time.now >count = 1 >File.open("data.txt") {|file| > file.each_line{|line| count += 1} >} >puts Time.now - t1 >puts count > >Using the each_line iterator from the file class removes the need for a >eof test. This should run quite a bit faster. Actually, if anything, it is slower. Very interesting ... Ronald E Jeffries http://www.XProgramming.com http://www.objectmentor.com I'm giving the best advice I have. You get to decide whether it's true for you.