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
Tue May 13 11:28:12 -0700 2008
commit  ff19a1ab25844042f02db0f769c9481810cc1357
tree    7e0d37a3a264788cf85977a3910b6799a442788d
parent  0b34508ccc8fe963bddb0635b9e16f363d6a4d12
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)