Skip to content

Instantly share code, notes, and snippets.

@fxn
Created February 9, 2012 10:32
Show Gist options
  • Save fxn/1779148 to your computer and use it in GitHub Desktop.
Save fxn/1779148 to your computer and use it in GitHub Desktop.
Top ten instantiated classes by instance count on Ruby 1.9.3 startup (MRI)
classes = Hash.new(0)
ObjectSpace.each_object do |object|
classes[object.class] += 1
end
top_ten = classes.values.uniq.sort.reverse[9]
classes.select {|_, c| c >= top_ten}.sort_by {|_, c| -c}.each do |klass, c|
puts "#{klass}: #{c}"
end
__END__
String: 5037
Array: 328
Class: 205
RubyVM::InstructionSequence: 198
MatchData: 108
Encoding: 99
RubyVM::Env: 37
Proc: 35
Regexp: 24
Module: 21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment