Permalink
Browse files

Add benchmark for Object#kind_of

  • Loading branch information...
1 parent b677890 commit fe93ffb236519816bb6ad98246ea8fcc14134150 @dbussink dbussink committed Nov 6, 2012
Showing with 38 additions and 0 deletions.
  1. +38 −0 benchmark/core/object/bench_kind_of.rb
@@ -0,0 +1,38 @@
+require 'benchmark'
+require 'benchmark/ips'
+
+Benchmark.ips do |x|
+
+ x.report "Fixnum#kind_of? => true" do |times|
+ i = 0
+ while i < times
+ 1.kind_of? Fixnum
+ i += 1
+ end
+ end
+
+ x.report "Fixnum#kind_of? => false" do |times|
+ i = 0
+ while i < times
+ 1.kind_of? String
+ i += 1
+ end
+ end
+
+ x.report "String#kind_of? => true" do |times|
+ i = 0
+ while i < times
+ "str".kind_of? String
+ i += 1
+ end
+ end
+
+ x.report "String#kind_of? => false" do |times|
+ i = 0
+ while i < times
+ "str".kind_of? Fixnum
+ i += 1
+ end
+ end
+
+end

0 comments on commit fe93ffb

Please sign in to comment.