[macruby-changes] [MacRuby/MacRuby] d5d1e6: reduce the memory usage in IO#read.
noreply at github.com
noreply at github.com
Wed Jun 1 05:05:01 PDT 2011
Branch: refs/heads/master
Home: https://github.com/MacRuby/MacRuby
Commit: d5d1e6f294dacf658b7c9fa4e3ae2effe7449315
https://github.com/MacRuby/MacRuby/commit/d5d1e6f294dacf658b7c9fa4e3ae2effe7449315
Author: Watson <watson1978 at gmail.com>
Date: 2011-06-01 (Wed, 01 Jun 2011)
Changed paths:
M io.c
Log Message:
-----------
reduce the memory usage in IO#read.
Result: (file size = 100 MB)
----
case before after
-------------------------------
case 1 : 426,120 KB 320,524 KB
case 2 : 117,312 KB 11,996 KB
{{{
def memory
pid = $$
str = `ps alx | grep '#{pid}.*ruby'`
str.split[7]
end
File.open("/tmp/foo", "r") {|f|
case ARGV[0].to_i
when 1
# case 1
f.read
when 2
# case 2
f.read(1024 * 1024)
else
raise "\n******** chose 1 or 2 ********\n"
end
}
puts memory + " KB"
}}}
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions
str = "foo\nbar\nbaz0123456789"
IO.pipe {|r, w|
w.write str
w.close
assert_equal(str, r.read)
}
IO.pipe {|r, w|
w.write str
w.close
assert_equal("fo", r.read(2))
}
require 'socket'
svr = TCPServer.new("localhost", 0)
th = Thread.new {
loop do
c = svr.accept
c.write str
c.close
end
}
addr = svr.addr
sock = TCPSocket.open(addr[3], addr[1])
assert_equal(str, sock.read)
sock.close
sock = TCPSocket.open(addr[3], addr[1])
assert_equal("fo", sock.gets("\n", 2))
assert_equal("o\nbar\nbaz0123456789", sock.read)
sock.close
puts :ok
}}}
More information about the macruby-changes
mailing list