From: Roger Pack Date: 2010-02-13T09:03:30+09:00 Subject: [ruby-core:28162] [Bug #2742] IO#read/gets can be very slow in doze Bug #2742: IO#read/gets can be very slow in doze http://redmine.ruby-lang.org/issues/show/2742 Author: Roger Pack Status: Open, Priority: Normal ruby -v: ruby 1.9.2dev (2010-02-12 trunk 26649) [i386-mingw32] this code n = 100 * 1000 * 1000 puts "writing" File.open("foo", 'wb'){|f| f.write(" " * n) } puts "reading" File.open("foo", 'r') do |io| io.read end takes something like 700s in windows, most of the time is spent in rb_str_resize. Cause seems to be that it is rb_str_resize'ing the string by 1024B at a time, so N^2 in the amount of time it takes to read it in because it has to keep copying it to the newly sized string. The same thing happens for File.open("foo", 'rb') do |io| io.gets end except that it reads (and resizes) in 8K bytes. Not sure why they're different sizes. I'd imagine this problem exists in Linux, but without as much of a negative impact as it reads in larger sizes. ---------------------------------------- http://redmine.ruby-lang.org