From: Michael Husmann Date: 2001-08-24T17:11:08+09:00 Subject: [ruby-talk:20259] Re: File.readline(s) Yukihiro Matsumoto wrote: > Hi, > > In message "[ruby-talk:20254] File.readline(s)" > on 01/08/24, Michael Husmann writes: > > |I am reading a 55MB ASCII file by using File.readline(s) which takes on > |my machine about 22s. The same runs in Python using readlines(0x2000) in > |about 9 seconds. Does anybody know whether there is a chance to speed > |things up in Ruby by reading chunks like in Python. > > There must be some bottleneck left, probably due to my stupidity. > Could you show me your slow Ruby code, and fast Python code? > > matz. Hi Matz, this is the code in Python: def read_blocks(name): lines = None line = "" n = 0 f = open(name) while 1: lines = f.readlines(0x2000) if not lines: break for line in lines: n += 1 return n and this in Ruby: def read_f(name) n = 0 line = "" f = File.open(name) f.each_line{|line| n += 1 } n end regards, Michael