Sha256: 74e40ac2adb29cb6e42848083d3a2bbb7c4b2d2db5150a2d070899ab33f50194

Contents?: true

Size: 681 Bytes

Versions: 12

Compression:

Stored size: 681 Bytes

Contents

#!/usr/bin/env ruby

# encoding: utf-8

# benchmark speed of deep freeze

$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)

require 'rbench'
require 'ice_nine'

# @return [Hash]
def self.nested(depth, width, array_length)
  hash = {}

  1.upto(width) do |n|
    hash[n.to_s] = n.to_s
  end

  unless depth == 1
    hash[(width - 1).to_s] = array_length.times.map { nested(depth - 1, width, array_length) }
    hash[width.to_s] = nested(depth - 1, width, array_length)
  end

  hash
end

hash = nested(3, 5, 500)
hash2 = nested(3, 5, 500)

RBench.run do
  report('deep_freeze')  { IceNine.deep_freeze(hash)   }
  report('deep_freeze!') { IceNine.deep_freeze!(hash2) }
end

Version data entries

12 entries across 10 versions & 4 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/ice_nine-0.11.2/benchmarks/speed.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/ice_nine-0.11.2/benchmarks/speed.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/ice_nine-0.11.2/benchmarks/speed.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/ice_nine-0.11.2/benchmarks/speed.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/ice_nine-0.11.2/benchmarks/speed.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/ice_nine-0.11.2/benchmarks/speed.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/ice_nine-0.11.2/benchmarks/speed.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/ice_nine-0.11.2/benchmarks/speed.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/ice_nine-0.11.2/benchmarks/speed.rb
ice_nine-0.11.2 benchmarks/speed.rb
ice_nine-0.11.1 benchmarks/speed.rb
ice_nine-0.11.0 benchmarks/speed.rb