Skip to content

Instantly share code, notes, and snippets.

@carloslopes
Last active January 13, 2021 15:46
Show Gist options
  • Save carloslopes/cf58b475b6ef608e86ecdb281a0d5d35 to your computer and use it in GitHub Desktop.
Save carloslopes/cf58b475b6ef608e86ecdb281a0d5d35 to your computer and use it in GitHub Desktop.
Simple memory used and time spent script
require 'benchmark'
class Analyzer
def self.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 self.print_time_spent
time = Benchmark.realtime do
yield
end
puts "Time: #{time.round(2)}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment