Skip to content

Instantly share code, notes, and snippets.

@we4tech
Created March 13, 2018 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save we4tech/07942c8042f5e0c4b2572f7a4646e280 to your computer and use it in GitHub Desktop.
Save we4tech/07942c8042f5e0c4b2572f7a4646e280 to your computer and use it in GitHub Desktop.
Find out ruby string generation
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