Skip to content

Instantly share code, notes, and snippets.

@lunich
Created April 11, 2011 18:41
Show Gist options
  • Save lunich/914031 to your computer and use it in GitHub Desktop.
Save lunich/914031 to your computer and use it in GitHub Desktop.
gsub! leak-test
SYMBOLS = ("a".."z").to_a
srand
def rand_word(len = 10)
SYMBOLS.sort_by { |_1,_2| rand <=> 0.5 }[0..(len-1)].join
end
was_affected = false
value = "some kind of initial value"
array_for_bulk_find_and_replace = (0..100_000).to_a.map { |c| [rand_word(3), rand_word(3)] }
array_for_bulk_find_and_replace.each_with_index do |replace_pair, i|
reg_val = replace_pair[0].to_s
was_affected |= "" != value.gsub!(/#{reg_val}/, replace_pair[1].to_s)
if 0 == (i+1) % 1000
puts %x{ps -p #{Process.pid} -o %mem,rss}
end
end
puts value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment