Created
September 16, 2015 18:32
-
-
Save inkel/d860eb86a6edf90ec787 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
#! /usr/bin/env ruby | |
GC.disable | |
require "objspace" | |
FMT = <<STATS.freeze | |
before %10d | |
after %10d | |
---------- | |
%10d | |
STATS | |
N = Integer(ARGV.first || 10_000) | |
def profile(&block) | |
GC.start | |
before = ObjectSpace.count_objects[:T_STRING] | |
N.times { block.call } | |
after = ObjectSpace.count_objects[:T_STRING] | |
puts FMT % [before, after, (after - before)] | |
GC.start | |
end | |
puts "Iterating #{N} times".freeze | |
puts | |
puts "String".freeze | |
profile { "lorem" } | |
puts | |
puts "Frozen string".freeze | |
profile { "ipsum".freeze } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment