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.34.0 benchs/params.rb
fog-1.33.0 benchs/params.rb
fog-1.32.0 benchs/params.rb
fog-1.31.0 benchs/params.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/fog-1.22.1/benchs/params.rb
fog-1.30.0 benchs/params.rb
fog-1.29.0 benchs/params.rb
fog-1.28.0 benchs/params.rb
fog-1.27.0 benchs/params.rb
fog-1.26.0 benchs/params.rb
fog-1.25.0 benchs/params.rb
nsidc-fog-1.24.1 benchs/params.rb
fog-1.24.0 benchs/params.rb
geemus-fog-0.0.0 benchs/params.rb
geemus-fog-0.0.1 benchs/params.rb
geemus-fog-0.0.3 benchs/params.rb
ns-fog-1.22.11 benchs/params.rb
ns-fog-1.22.10 benchs/params.rb
ns-fog-1.22.9 benchs/params.rb
ns-fog-1.22.8 benchs/params.rb