Created
September 28, 2013 20:46
-
-
Save vipulnsward/6746362 to your computer and use it in GitHub Desktop.
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
# Object Counter for use in example on vipulnsward.com about Frozen | |
# Strings in Ruby | |
module ObjectCounter | |
def self.count | |
GC.disable | |
before_count = ObjectSpace.count_objects | |
yield | |
after_count = ObjectSpace.count_objects | |
after_count.each do |k,v| | |
after_count[k] = v.to_i - before_count[k].to_i | |
end | |
GC.enable | |
after_count | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment