Created
May 20, 2020 19:31
-
-
Save VasylShevchenko/0777fbb71a95c02f06beeb3205263f29 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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