Skip to content

Instantly share code, notes, and snippets.

@raulsouzalima
Last active October 4, 2017 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raulsouzalima/84909371bec495f57622d52e7dc66145 to your computer and use it in GitHub Desktop.
Save raulsouzalima/84909371bec495f57622d52e7dc66145 to your computer and use it in GitHub Desktop.
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