anildigital (owner)

Revisions

gist: 134449 Download_button fork
public
Public Clone URL: git://gist.github.com/134449.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
require 'test/unit'
require 'benchmark'
 
class HasKey < Test::Unit::TestCase
  def test_has_key
    hash = {:a => nil, :b => nil, :c => nil, :d => nil, :e => nil, :f => nil,
      :g => nil, :h => nil, :i => nil, :j => nil, :k => nil, :z => nil,
      :m => nil, :n => nil, :o => nil, :p => nil, :q => nil, :r => nil,
      :s => nil, :t => nil,}
    array = [1,2,2,4,5,3,64,534,6,3,6,7,3,63,8,84,31,46,61,90]
 
    Benchmark.bm(1000) do |r|
      r.report("array include"){ array.include?(3)}
      r.report("hash key") {hash.has_key?(:b)}
    end
  end
end