-
-
Save jerodsanto/46442 to your computer and use it in GitHub Desktop.
Revisions
-
There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ 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"