From: Peter Hickman Date: 2002-03-07T22:32:42+09:00 Subject: Re: file reading impossibly slow? Your file reading is a bit non-ruby, so to speak, you need to get the hang of itterators. 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. Ron Jeffries wrote: >The file ran in 2229.656 seconds, or 37 minutes. Smalltalk was 3 minutes. >Program was > >t1 = Time.now >count = 1 >File.open("data.txt") { | file | > while (!file.eof?) > line = file.gets > count += 1 > end >} >puts Time.now - t1 >puts count > >Got the wrong answer, too. Should have said count = 0 ;-> > >What's a guy to think? That seems awfully slow ... > >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. >