Skip to content

Instantly share code, notes, and snippets.

@SamSaffron
Created February 19, 2014 05:00
Show Gist options
  • Save SamSaffron/9086296 to your computer and use it in GitHub Desktop.
Save SamSaffron/9086296 to your computer and use it in GitHub Desktop.
@retained = []
MAX_STRING_SIZE = 100
def stress(allocate_count, retain_count, chunk_size)
chunk = []
while retain_count > 0 || allocate_count > 0
if retain_count == 0 || (Random.rand < 0.5 && allocate_count > 0)
chunk << " " * (Random.rand * MAX_STRING_SIZE).to_i
allocate_count -= 1
if chunk.length > chunk_size
chunk = []
end
else
@retained << " " * (Random.rand * MAX_STRING_SIZE).to_i
retain_count -= 1
end
end
end
start = Time.now
stress(10_000_000, 600_000, 200_000)
puts "Duration: #{(Time.now - start).to_f}"
# GC.start
# p GC.stat
puts `ps aux | grep #{Process.pid} | grep -v grep`
@SamSaffron
Copy link
Author

Ruby 2.0: 151120 RSS
Ruby 2.1.0 : 267076 RSS

@SamSaffron
Copy link
Author

WITHOUT THREEGEN

sam@ubuntu ~ % ruby stress_mem.rb
Duration: 5.355337084
sam 18567 89.6 3.8 267532 238356 pts/14 Sl+ 16:20 0:05 ruby stress_mem.rb

WITH THREEGEN

sam@ubuntu ~ % ruby stress_mem.rb
Duration: 4.468102349
sam 18612 112 2.4 178928 148624 pts/14 Sl+ 16:21 0:04 ruby stress_mem.rb

RSS reduced from 238mb to 148mb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment