Bug #2722: gets on a large file takes a very very long time
http://redmine.ruby-lang.org/issues/show/2722

Author: Greg Hazel
Status: Open, Priority: Normal
ruby -v: ruby 1.8.6 (2009-08-04 patchlevel 383) [i386-mingw32]

This problem occurs on 1.8.6, 1.8.7 and 1.9.1 (all the versions I tested)

This simple script demonstrates the problem:

# 100 MB
n = 100 * 1000 * 1000
puts "writing"
File.open("foo", 'wb'){|f| f.write(" " * n) }
puts "reading"
File.open("foo", 'rb') do |io|
  io.gets
end

This takes about 1911 seconds. Using a 10MB file completes in 19 seconds, instead of in 1/10th the time as you would imagine. Similarly a 1MB file completes in 0.18 seconds.


----------------------------------------
http://redmine.ruby-lang.org