Skip to content

Instantly share code, notes, and snippets.

@mec
Created April 26, 2019 20:40
Show Gist options
  • Select an option

  • Save mec/24d4e97b679fcccdd7f787a2034ad02e to your computer and use it in GitHub Desktop.

Select an option

Save mec/24d4e97b679fcccdd7f787a2034ad02e to your computer and use it in GitHub Desktop.
Rails perf helper
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment