public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
Sun May 11 14:17:29 -0700 2008
commit  af548c0808576118ffbb43468104146feb7acbf9
tree    4b1a608fd28f0ae9a47797745d96eaf4e4b94dbb
parent  714a73910a39bdb733116dacab301c61d38edf07 parent  f8df510045587cd49a78851c1c6fc17a0e333a7d
merb-core / simple_benches / set_hash.rb
100644 31 lines (27 sloc) 1.371 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require 'set'
require 'benchmark'
require 'forwardable'
 
TIMES = (ARGV[0] || 100_000).to_i
 
hsh = {:x => true, :y => true}
set = Set.new([:x, :y])
fst = FasterSet.new([:x, :y])
 
Benchmark.bmbm do |x|
  x.report("current included") { TIMES.times { hsh[:x] } }
  x.report("hash included") { TIMES.times { hsh.include?(:x) } }
  x.report("set included") { TIMES.times { set.include?(:x) } }
  x.report("fasterset included") { TIMES.times { fst.include?(:x) } }
  x.report("current !included") { TIMES.times { hsh[:z] } }
  x.report("hash !included") { TIMES.times { hsh.include?(:z) } }
  x.report("set !included") { TIMES.times { set.include?(:z) } }
  x.report("fasterset !included") { TIMES.times { fst.include?(:z) } }
end
 
# TIMES = 1_000_000
# user system total real
# current included 0.400000 0.000000 0.400000 ( 0.400513)
# hash included 0.390000 0.000000 0.390000 ( 0.396909)
# set included 1.060000 0.000000 1.060000 ( 1.055078)
# fasterset included 0.400000 0.000000 0.400000 ( 0.401823)
# current !included 0.510000 0.000000 0.510000 ( 0.508479)
# hash !included 0.400000 0.000000 0.400000 ( 0.400109)
# set !included 1.050000 0.010000 1.060000 ( 1.062367)
# fasterset !included 0.400000 0.000000 0.400000 ( 0.399415)