Created
February 7, 2012 12:12
-
-
Save bil-bas/1759408 to your computer and use it in GitHub Desktop.
Count objects
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
module GC | |
def self.count_objects_by_class | |
@@runs ||= [] | |
run = Hash.new 0 | |
@@runs << run | |
# Count objects of each class. | |
ObjectSpace.each_object do |obj| | |
run[obj.class.name.to_sym] += 1 | |
end | |
# List classes and number of them in each run. | |
@@runs.map(&:keys).flatten.uniq.sort.each do |klass| | |
puts "#{klass} #{@@runs.map {|r| r[klass] }}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment