Sha256: 954545626c52f12fb267566f76fe17e81dbde8342809600062f43b24418233e1

Contents?: true

Size: 875 Bytes

Versions: 350

Compression:

Stored size: 875 Bytes

Contents

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

Version data entries

350 entries across 348 versions & 28 rubygems

Version Path
fog-1.19.0 benchs/params.rb
fog-maestrodev-1.18.0.20131219033443 benchs/params.rb
fog-maestrodev-1.18.0.20131219032002 benchs/params.rb
fog-maestrodev-1.18.0.20131219030716 benchs/params.rb
fog-maestrodev-1.18.0.20131219022322 benchs/params.rb
fog-maestrodev-1.18.0.20131218202447 benchs/params.rb
fog-maestrodev-1.18.0.20131209091424 benchs/params.rb
fog-maestrodev-1.18.0.20131209090811 benchs/params.rb
fog-maestrodev-1.18.0.20131206115947 benchs/params.rb
fog-maestrodev-1.18.0.20131205181604 benchs/params.rb
fog-maestrodev-1.18.0.20131127194823 benchs/params.rb
fog-maestrodev-1.18.0.20131126183714 benchs/params.rb
fog-maestrodev-1.18.0.20131126122111 benchs/params.rb
fog-maestrodev-1.18.0.20131125111730 benchs/params.rb
fog-maestrodev-1.18.0.20131125083406 benchs/params.rb
fog-maestrodev-1.18.0.20131123105121 benchs/params.rb
fog-maestrodev-1.18.0.20131122203507 benchs/params.rb
fog-maestrodev-1.18.0.20131121075022 benchs/params.rb
fog-maestrodev-1.18.0.20131118164830 benchs/params.rb
fog-maestrodev-1.18.0.20131115184302 benchs/params.rb