Last active
October 4, 2017 21:27
-
-
Save raulsouzalima/84909371bec495f57622d52e7dc66145 to your computer and use it in GitHub Desktop.
This file contains 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 "benchmark" | |
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 | |
print_memory_usage do | |
print_time_spent do | |
"...code..." | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment