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
Search Repo:
Michael S. Klishin (author)
Tue May 13 11:34:51 -0700 2008
commit  137889807100ed854a43e663ae2ea33fb2eea6ce
tree    06ca2a8bf6da47309d6928edf2ff5a14ab9cce65
parent  ff19a1ab25844042f02db0f769c9481810cc1357
merb-core / simple_benches / imethod_exists.rb
100644 33 lines (30 sloc) 1.144 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
32
33
require 'benchmark'
 
TIMES = (ARGV[0] || 10_000).to_i
 
Benchmark.bmbm do |x|
  x.report("instance_methods.include? == true") do
    TIMES.times do
      Class.instance_methods.include?(:to_s) || Class.instance_methods.include?("to_s")
    end
  end
  x.report("instance_method() rescue nil == true") do
    TIMES.times do
      Class.instance_method(:to_s) rescue false
    end
  end
  x.report("instance_methods.include? == false") do
    TIMES.times do
      Class.instance_methods.include?(:foo) || Class.instance_methods.include?("foo")
    end
  end
  x.report("instance_method() rescue nil == false") do
    TIMES.times do
      Class.instance_method(:foo) rescue false
    end
  end
end
 
# TIMES = 10_000
# user system total real
# instance_methods.include? == true 1.790000 0.010000 1.800000 ( 1.805433)
# intance_method() rescue nil == true 0.010000 0.000000 0.010000 ( 0.008334)
# instance_methods.include? == false 1.810000 0.000000 1.810000 ( 1.818613)
# intance_method() rescue nil == true 0.130000 0.010000 0.140000 ( 0.135678)