Permalink
Browse files

Added benchmark.

  • Loading branch information...
1 parent 3452cb6 commit 5affde62d7b29fe6bfc8f048e28e5c5953215e15 Kaoru Kobo committed Dec 1, 2010
Showing with 81 additions and 0 deletions.
  1. +43 −0 examples/benchmark_empty_method.rb
  2. +38 −0 examples/benchmark_logger.rb
@@ -0,0 +1,43 @@
+require "rubygems"
+# $LOAD_PATH.unshift(File.dirname(__FILE__)+"/../lib")
+require "rhook"
+
+require "benchmark"
+
+class Target
+ def target
+
+ end
+end
+
+n = 30000
+Benchmark.bm(24) do |x|
+ t = Target.new
+
+ doit = lambda do
+ n.times do
+ t.target
+ end
+ end
+
+ # ========================================================================
+ x.report("direct:") do
+ doit.call
+ end
+
+ # ========================================================================
+ hook = Target._rhook.hack(:target) do |inv|
+ inv.call
+ end
+
+ x.report("rhook enabled:") do
+ doit.call
+ end
+
+ # ========================================================================
+ hook.disable
+
+ x.report("rhook disabled:") do
+ doit.call
+ end
+end
@@ -0,0 +1,38 @@
+require "rubygems"
+# $LOAD_PATH.unshift(File.dirname(__FILE__)+"/../lib")
+require "rhook"
+
+require "benchmark"
+require "logger"
+
+n = 30000
+Benchmark.bm(24) do |x|
+ logger = Logger.new(open("/dev/null", "w"))
+
+ doit = lambda do
+ n.times do
+ logger.info("msg")
+ end
+ end
+
+ # ========================================================================
+ x.report("direct:") do
+ doit.call
+ end
+
+ # ========================================================================
+ hook = Logger._rhook.hack(:add) do |inv|
+ inv.call
+ end
+
+ x.report("rhook enabled:") do
+ doit.call
+ end
+
+ # ========================================================================
+ hook.disable
+
+ x.report("rhook disabled:") do
+ doit.call
+ end
+end

0 comments on commit 5affde6

Please sign in to comment.