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-2.3.0 benchs/params.rb
fog-ifeel-2.2.0 benchs/params.rb
fog-2.2.0 benchs/params.rb
fog-2.1.0 benchs/params.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/fog-1.42.1/benchs/params.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-1.42.1/benchs/params.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/fog-1.42.1/benchs/params.rb
fog-1.42.1 benchs/params.rb
fog-2.0.0 benchs/params.rb
fog-1.42.0 benchs/params.rb
fog-1.41.0 benchs/params.rb
fog-1.40.0 benchs/params.rb
fog-1.39.0 benchs/params.rb
fog-digitalocean-0.1.0 benchs/params.rb
fog-1.38.0 benchs/params.rb
fog-1.37.0 benchs/params.rb
fog-1.36.0 benchs/params.rb
fog-1.35.0 benchs/params.rb
fog-2.0.0.pre.0 benchs/params.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/fog-1.32.0/benchs/params.rb