Last active
April 25, 2018 22:20
-
-
Save EdgarOrtegaRamirez/8fd5c97f8c96884f38b049999df90dc7 to your computer and use it in GitHub Desktop.
Ruby Memory and Time Usage script
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
def print_memory_usage | |
memory_before = `ps -o rss= -p #{Process.pid}`.to_i | |
yield | |
memory_after = `ps -o rss= -p #{Process.pid}`.to_i | |
puts "Memory: #{((memory_after - memory_before) / 1024.0).round(2)} MB" | |
end | |
def print_time_spent | |
time = Benchmark.realtime do | |
yield | |
end | |
puts "Time: #{time.round(2)}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment