-
-
Save rrichards/119749 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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