Created
February 21, 2011 00:30
-
-
Save raggi/836470 to your computer and use it in GitHub Desktop.
Show the effects of rubygems source_index load on in-memory string size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RAW = true # flip me to make the logs readable, for interests sake. | |
def write_strings_to fn | |
open(fn, 'w+') do |f| | |
ObjectSpace.each_object do |o| | |
f.send((RAW ? :print : :puts), o) if o.class == String | |
end | |
end | |
end | |
file = %w[strings_no_gems.log strings_gems_no_gc.log strings_gems.log] | |
GC.start | |
write_strings_to file[ 0 ] | |
require 'rubygems' | |
Gem.source_index.find { |_,spec| } | |
write_strings_to file[ 1 ] | |
GC.start | |
write_strings_to file[ 2 ] | |
last = File.size file[ 0 ] | |
file.each do |fn| | |
cur = File.size(fn).to_f | |
pcge = cur / last * 100 | |
puts "#%26s: %15d bytes, change: %8d%" % [fn, cur, pcge] | |
last = cur | |
end |
N.B. You may need to run: https://gist.github.com/836462 to get the above effect (after installing rubygems 1.6/master).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Before RubyGems 1.6:
After RubyGems 1.6: