Created
March 13, 2018 14:35
-
-
Save we4tech/07942c8042f5e0c4b2572f7a4646e280 to your computer and use it in GitHub Desktop.
Find out ruby string generation
This file contains hidden or 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
require 'pp' | |
def profile | |
old_strs = ObjectSpace.count_objects[:T_STRING] | |
old_objs = GC.stat[:total_allocated_objects] | |
yield.tap do | |
new_strs = ObjectSpace.count_objects[:T_STRING] | |
new_objs = GC.stat[:total_allocated_objects] | |
puts <<-STR | |
Total allocated objects: #{new_objs - old_objs} | |
Total strings: #{new_strs - old_strs} | |
STR | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment