Sha256: 189ca8fc6f30e841398068741fd9d6e94498e2c4c3f87ab599c92a5af021fbac

Contents?: true

Size: 1.56 KB

Versions: 4

Compression:

Stored size: 1.56 KB

Contents

require '../ext/google_hash'
require 'benchmark'
require 'hitimes' # gem
require 'sane' # gem

def measure
 Hitimes::Interval.measure { yield }
end

def meas string
 time_took = measure { yield }
 puts "% -23s %.03f" % [string, time_took]
end

def go num
  puts RUBY_DESCRIPTION
  puts "inserting #{num} objects"
  puts "remember that these may be more RAM space efficient than ruby's standard hash, as well, esp. the sparse hash, and that it has specialized hashes to deal with the case of just using integers for keys, etc."
  puts "double is like float, long is like a large int"
  # get all existing
  all_google_hashmap_classes = Object.constants.grep(/Goog/).reject{|n| n == :GoogleHash}.map{|n| eval n.to_s}
  all = [Hash] + all_google_hashmap_classes

  for name in all do
    GC.start
    subject = name.new
    puts
	if name == Hash
      puts "Ruby Standard Hash"
	else
	  puts name
	end

    subject = name.new
    meas( "populate string ") { num.times {|n| subject['abc'] = 4 } } rescue nil
    subject = name.new
    meas( "populate symbol") { num.times {|n| subject[:abc] = 4} } rescue nil

    meas( "populate integer") { num.times {|n| subject[n] = 4}}
    meas("#each") { subject.each{|k, v| } }

    begin
      subject = name.new
      subject[3] = 4
      meas("lookup int") { num.times {|n| subject[3]}}
      subject['abc'] = 3
      subject[:abc] = 3

      meas("lookup string")  { num.times {|n| subject['abc']}}
      meas( "lookup symbol" ) { num.times {|n| subject[:abc]}}
    rescue # most don't support these...
    end
  end
end

num = 400_000
go num if $0 ==__FILE__

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
google_hash-0.8.2 spec/benchmark.rb
google_hash-0.8.1 spec/benchmark.rb
google_hash-0.8.0 spec/benchmark.rb
google_hash-0.7.0 spec/benchmark.rb