1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/benchs/load_times.rb
2013-03-28 11:45:41 -04:00

31 lines
570 B
Ruby

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
N = 10
report("require fog:", N) { require 'fog' }
report("require fog/aws:", N) { require 'fog/aws' }