Skip to content

Instantly share code, notes, and snippets.

@floere
Last active August 29, 2015 13:56
Show Gist options
  • Save floere/9111529 to your computer and use it in GitHub Desktop.
Save floere/9111529 to your computer and use it in GitHub Desktop.
Assigning nil values to 1'000'000 string keys: Memory usage comparison between MRI Ruby 1.9.3 and 2.1.0
chruby 1.9.3
ruby hashmemtest1.rb
ruby hashmemtest2.rb
ruby hashmemtest3.rb
chruby 2.1.0
ruby hashmemtest1.rb
ruby hashmemtest2.rb
ruby hashmemtest3.rb
GC.start
h = {}
10.times do |i|
1000000.times do |i|
h[i.to_s] = nil
end
puts "#{"%5i" % i} #{`ps aux | grep -e 'ruby' | grep -v grep`}"
end
GC.start
h = {}
10.times do |i|
h.clear
1000000.times do |i|
h[i.to_s] = nil
end
puts "#{"%5i" % i} #{`ps aux | grep -e 'ruby' | grep -v grep`}"
end
GC.start
h = {}
10.times do |i|
1000000.times do |i|
h[%q{i}.freeze] = nil
end
puts "#{"%5i" % i} #{`ps aux | grep -e 'ruby' | grep -v grep`}"
end
Versions used:
ruby 1.9.3dev (2011-09-23 revision 33323) [x86_64-darwin12.2.1]
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin13.0]
hanke@soyuz:hashmemtest: chruby 1.9.3
hanke@soyuz:hashmemtest: ruby hashmemtest1.rb
0 hanke 60656 98.8 0.8 2590792 130640 s004 S+ 12:39PM 0:01.04 ruby hashmemtest1.rb
1 hanke 60656 97.1 0.8 2590792 130648 s004 S+ 12:39PM 0:01.70 ruby hashmemtest1.rb
2 hanke 60656 99.4 0.8 2590792 130648 s004 S+ 12:39PM 0:02.36 ruby hashmemtest1.rb
3 hanke 60656 100.0 0.8 2590792 130648 s004 S+ 12:39PM 0:03.04 ruby hashmemtest1.rb
4 hanke 60656 98.5 0.8 2590792 130648 s004 S+ 12:39PM 0:03.70 ruby hashmemtest1.rb
5 hanke 60656 100.0 0.8 2590792 130648 s004 S+ 12:39PM 0:04.38 ruby hashmemtest1.rb
6 hanke 60656 97.9 0.8 2590792 130648 s004 S+ 12:39PM 0:05.06 ruby hashmemtest1.rb
7 hanke 60656 97.1 0.8 2590792 130648 s004 S+ 12:39PM 0:05.74 ruby hashmemtest1.rb
8 hanke 60656 98.1 0.8 2590792 130648 s004 S+ 12:39PM 0:06.42 ruby hashmemtest1.rb
9 hanke 60656 100.0 0.8 2590792 130648 s004 S+ 12:39PM 0:07.15 ruby hashmemtest1.rb
hanke@soyuz:hashmemtest: ruby hashmemtest2.rb
0 hanke 60705 99.0 0.8 2597960 130636 s004 S+ 12:39PM 0:01.02 ruby hashmemtest2.rb
1 hanke 60705 100.0 0.8 2598988 131112 s004 S+ 12:39PM 0:02.10 ruby hashmemtest2.rb
2 hanke 60705 99.3 0.8 2601036 137392 s004 S+ 12:39PM 0:03.16 ruby hashmemtest2.rb
3 hanke 60705 98.6 0.9 2601040 145568 s004 S+ 12:39PM 0:04.24 ruby hashmemtest2.rb
4 hanke 60705 100.0 0.9 2598992 147992 s004 S+ 12:39PM 0:05.44 ruby hashmemtest2.rb
5 hanke 60705 100.0 0.9 2600016 152920 s004 S+ 12:39PM 0:06.59 ruby hashmemtest2.rb
6 hanke 60705 99.5 0.9 2597968 157252 s004 S+ 12:39PM 0:07.73 ruby hashmemtest2.rb
7 hanke 60705 100.0 0.9 2598992 157928 s004 S+ 12:39PM 0:09.04 ruby hashmemtest2.rb
8 hanke 60705 99.9 0.9 2600016 158720 s004 S+ 12:39PM 0:10.18 ruby hashmemtest2.rb
9 hanke 60705 98.8 0.9 2597968 157952 s004 S+ 12:39PM 0:11.33 ruby hashmemtest2.rb
hanke@soyuz:hashmemtest: ruby hashmemtest3.rb
0 hanke 60757 59.1 0.0 2464828 6140 s004 S+ 12:39PM 0:00.30 ruby hashmemtest3.rb
1 hanke 60757 83.1 0.0 2464828 6144 s004 S+ 12:39PM 0:00.57 ruby hashmemtest3.rb
2 hanke 60757 86.4 0.0 2465852 6156 s004 S+ 12:39PM 0:00.85 ruby hashmemtest3.rb
3 hanke 60757 92.2 0.0 2465852 6156 s004 S+ 12:39PM 0:01.12 ruby hashmemtest3.rb
4 hanke 60757 88.6 0.0 2465852 6156 s004 S+ 12:39PM 0:01.39 ruby hashmemtest3.rb
5 hanke 60757 92.4 0.0 2466876 6168 s004 S+ 12:39PM 0:01.67 ruby hashmemtest3.rb
6 hanke 60757 90.9 0.0 2476092 6188 s004 S+ 12:39PM 0:01.96 ruby hashmemtest3.rb
7 hanke 60757 88.3 0.0 2477116 6200 s004 S+ 12:39PM 0:02.27 ruby hashmemtest3.rb
8 hanke 60757 90.1 0.0 2477116 6200 s004 S+ 12:39PM 0:02.58 ruby hashmemtest3.rb
9 hanke 60757 89.5 0.0 2477116 6200 s004 S+ 12:39PM 0:02.88 ruby hashmemtest3.rb
hanke@soyuz:hashmemtest: chruby 2.1.0
hanke@soyuz:hashmemtest: ruby hashmemtest1.rb
0 hanke 60816 97.9 0.8 2632540 134160 s004 S+ 12:40PM 0:01.14 ruby hashmemtest1.rb
1 hanke 60816 99.4 1.0 2658140 166364 s004 S+ 12:40PM 0:01.84 ruby hashmemtest1.rb
2 hanke 60816 99.6 1.0 2658140 166372 s004 S+ 12:40PM 0:02.53 ruby hashmemtest1.rb
3 hanke 60816 97.6 1.0 2658140 166376 s004 S+ 12:40PM 0:03.22 ruby hashmemtest1.rb
4 hanke 60816 99.2 1.0 2658140 166376 s004 S+ 12:40PM 0:03.88 ruby hashmemtest1.rb
5 hanke 60816 97.5 1.0 2658140 166380 s004 S+ 12:40PM 0:04.57 ruby hashmemtest1.rb
6 hanke 60816 98.9 1.0 2658140 166380 s004 S+ 12:40PM 0:05.27 ruby hashmemtest1.rb
7 hanke 60816 96.6 1.0 2658140 166380 s004 S+ 12:40PM 0:05.93 ruby hashmemtest1.rb
8 hanke 60816 99.0 1.0 2658140 166380 s004 S+ 12:40PM 0:06.59 ruby hashmemtest1.rb
9 hanke 60816 99.1 1.0 2658140 166384 s004 S+ 12:40PM 0:07.25 ruby hashmemtest1.rb
hanke@soyuz:hashmemtest: ruby hashmemtest2.rb
0 hanke 60874 98.1 0.8 2616156 133908 s004 S+ 12:40PM 0:00.99 ruby hashmemtest2.rb
1 hanke 60874 100.0 1.2 2708316 208988 s004 S+ 12:40PM 0:02.20 ruby hashmemtest2.rb
2 hanke 60874 99.7 1.6 2791268 268456 s004 S+ 12:40PM 0:03.41 ruby hashmemtest2.rb
3 hanke 60874 100.0 1.6 2790244 269620 s004 S+ 12:40PM 0:04.75 ruby hashmemtest2.rb
4 hanke 60874 100.0 1.6 2790244 269636 s004 S+ 12:40PM 0:05.96 ruby hashmemtest2.rb
5 hanke 60874 100.0 1.6 2790244 269636 s004 S+ 12:40PM 0:07.18 ruby hashmemtest2.rb
6 hanke 60874 100.0 1.5 2765668 251196 s004 S+ 12:40PM 0:08.49 ruby hashmemtest2.rb
7 hanke 60874 100.0 1.5 2757476 245044 s004 S+ 12:40PM 0:09.69 ruby hashmemtest2.rb
8 hanke 60874 99.6 1.5 2758500 245296 s004 S+ 12:40PM 0:10.83 ruby hashmemtest2.rb
9 hanke 60874 97.7 1.4 2742116 241972 s004 S+ 12:40PM 0:12.01 ruby hashmemtest2.rb
hanke@soyuz:hashmemtest: ruby hashmemtest3.rb
0 hanke 60924 36.3 0.0 2475856 7632 s004 S+ 12:40PM 0:00.17 ruby hashmemtest3.rb
1 hanke 60924 46.1 0.0 2484048 7640 s004 S+ 12:40PM 0:00.28 ruby hashmemtest3.rb
2 hanke 60924 53.5 0.0 2484048 7640 s004 S+ 12:40PM 0:00.39 ruby hashmemtest3.rb
3 hanke 60924 66.5 0.0 2484048 7644 s004 S+ 12:40PM 0:00.51 ruby hashmemtest3.rb
4 hanke 60924 61.2 0.0 2484048 7644 s004 S+ 12:40PM 0:00.63 ruby hashmemtest3.rb
5 hanke 60924 69.7 0.0 2484048 7644 s004 S+ 12:40PM 0:00.74 ruby hashmemtest3.rb
6 hanke 60924 67.2 0.0 2484048 7644 s004 S+ 12:40PM 0:00.87 ruby hashmemtest3.rb
7 hanke 60924 63.9 0.0 2484048 7648 s004 S+ 12:40PM 0:00.98 ruby hashmemtest3.rb
8 hanke 60924 74.8 0.0 2485072 7660 s004 S+ 12:40PM 0:01.10 ruby hashmemtest3.rb
9 hanke 60924 65.3 0.0 2485072 7660 s004 S+ 12:40PM 0:01.22 ruby hashmemtest3.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment