1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/benchs/params.rb
2009-07-09 23:22:02 -07:00

43 lines
875 B
Ruby

require 'benchmark'
def hash(options)
result = "#{options.delete(:name)}"
for key, value in options
result << " #{key} => #{value} "
end
result
end
def optional(name, a = nil, b = nil, c = nil)
result = "#{name}"
options = { :a => a, :b => b, :c => c }
for key, value in options
result << " #{key} => #{value} "
end
result
end
COUNT = 100_000
data = "Content-Length: 100"
Benchmark.bmbm(25) do |bench|
bench.report('hash') do
COUNT.times do
hash({:name => 'name'})
end
end
bench.report('optional') do
COUNT.times do
optional('name')
end
end
bench.report('hash_with_option') do
COUNT.times do
hash({:name => 'name', :a => 'a', :b => 'b', :c => 'c'})
end
end
bench.report('optional_with_option') do
COUNT.times do
optional('name', :a => 'a', :b => 'b', :c => 'c')
end
end
end