Created
July 9, 2010 14:58
-
-
Save tjsingleton/469567 to your computer and use it in GitHub Desktop.
benchmark showing that symbols live forever
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
100000 Strings | |
After Block: 3318 | |
After Forced GC: 31 | |
100000 Symobls | |
After Block: 1519 | |
After Forced GC: 98619 |
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
N = 100_000 | |
puts "#{N} Strings" | |
GC.start | |
start = ObjectSpace.count_objects[:T_STRING] | |
N.times {|i| "#{i}" } | |
pre_gc_count = ObjectSpace.count_objects[:T_STRING] - start | |
GC.start | |
post_gc_count = ObjectSpace.count_objects[:T_STRING] - start | |
puts "After Block: #{pre_gc_count}" | |
puts "After Forced GC: #{post_gc_count}" | |
puts | |
puts "#{N} Symbols" | |
GC.start | |
pre_gc_count = Symbol.all_symbols.count | |
N.times {|i| "#{i}".intern } | |
diff = Symbol.all_symbols.count - start | |
GC.start | |
post_gc_count = Symbol.all_symbols.count - start | |
puts "After Block: #{pre_gc_count}" | |
puts "After Forced GC: #{post_gc_count}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment