2013-03-28 17:39:04 +04:00
|
|
|
require 'benchmark'
|
|
|
|
$LOAD_PATH << File.dirname(__FILE__) + '/../lib'
|
|
|
|
|
|
|
|
def time_in_fork(&block)
|
|
|
|
read, write = IO.pipe
|
|
|
|
Process.fork do
|
|
|
|
write.puts Benchmark.realtime{ block.call }
|
|
|
|
end
|
|
|
|
Process.wait
|
|
|
|
write.close
|
|
|
|
read.read.tap do
|
|
|
|
read.close
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Array
|
|
|
|
def avg
|
|
|
|
map(&:to_f).inject(:+) / size
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def report(label, n = 10, &block)
|
|
|
|
puts label
|
|
|
|
puts "%.4f" % n.times.map{ time_in_fork &block }.avg
|
|
|
|
puts
|
|
|
|
end
|
|
|
|
|
2014-02-02 06:29:35 +04:00
|
|
|
# make rubygems load specifications now so the
|
|
|
|
# time is not included below.
|
|
|
|
Gem::Specification._all
|
|
|
|
|
2013-03-28 17:39:04 +04:00
|
|
|
N = 10
|
|
|
|
|
|
|
|
report("require fog:", N) { require 'fog' }
|
|
|
|
report("require fog/aws:", N) { require 'fog/aws' }
|
2014-02-02 06:29:35 +04:00
|
|
|
report("require fog/aws/compute:", N) { require 'fog/aws/compute' }
|
|
|
|
report("require fog/aws/core:", N) { require 'fog/aws/core'}
|