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

44 lines
875 B
Ruby
Raw Normal View History

2009-07-10 02:22:02 -04:00
require 'benchmark'
2009-06-23 23:55:57 -04:00
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