Skip to content

Instantly share code, notes, and snippets.

@VasylShevchenko
Created May 20, 2020 19:31
Show Gist options
  • Save VasylShevchenko/0777fbb71a95c02f06beeb3205263f29 to your computer and use it in GitHub Desktop.
Save VasylShevchenko/0777fbb71a95c02f06beeb3205263f29 to your computer and use it in GitHub Desktop.
require "get_process_mem"
def print_usage(description)
mb = GetProcessMem.new.mb
puts "#{ description } - MEMORY USAGE(MB): #{ mb.round }"
end
def print_usage_before_and_after
print_usage("Before")
yield
print_usage("After")
end
def random_name
(0...20).map { (97 + rand(26)).chr }.join
end
# v1
ARRAY_SIZE = 1_000_000
times = 20
print_usage(0)
(1..times).each do |n|
foo = []
ARRAY_SIZE.times { foo << {some: "stuff"} }
print_usage(n)
end
# v2
# ARRAY_SIZE = 1_000_000
# times = 20
# foo = []
# print_usage(0)
# (1..times).each do |n|
#
# print_usage_before_and_after do
# ARRAY_SIZE.times { foo << {some: "stuff"} }
# end
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment