Skip to content

Instantly share code, notes, and snippets.

@jerodsanto
Forked from adamwiggins/gemweight.rb
Created January 13, 2009 13: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 jerodsanto/46442 to your computer and use it in GitHub Desktop.
Save jerodsanto/46442 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'benchmark'
gem = ARGV.shift.strip rescue ''
if gem == ''
STDERR.puts "usage: #{$0} [gem]"
exit 1
end
`free`
if $? != 0
STDERR.puts "This program only works on Linux (or other unixes with the \"free\" command)."
STDERR.puts "If you can figure out a way to get this to work on OS X, please send me a patch!"
exit 1
end
def free_mem
`free -b`.match(/Mem:\s*\d+\s*(\d+)/)[1].to_i
end
KB = 1024
MB = 1024 * KB
GB = 1024 * MB
def bytes(amount)
return nil if amount.nil?
return "#{amount} bytes" if amount < KB
return "#{(amount / KB).round}kb" if amount < MB
return "#{(amount / MB).round}MB" if amount < GB
return "#{(amount / GB).round}GB"
end
before = free_mem
time = Benchmark.measure { require gem }.real
after = free_mem
used = after - before
time = sprintf("%0.02f", time)
puts "#{gem} uses #{bytes(used)} and takes #{time}s to load"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment