Skip to content

Instantly share code, notes, and snippets.

@EdgarOrtegaRamirez
Last active April 25, 2018 22:20
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 EdgarOrtegaRamirez/8fd5c97f8c96884f38b049999df90dc7 to your computer and use it in GitHub Desktop.
Save EdgarOrtegaRamirez/8fd5c97f8c96884f38b049999df90dc7 to your computer and use it in GitHub Desktop.
Ruby Memory and Time Usage script
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