Permalink
Browse files

Merge branch 'JoelJuliano/master'

  • Loading branch information...
2 parents a8c870a + 258f64f commit 2d77b2fa9e856b5be0018fb123a07dabdaa5e720 @kristianmandrup committed Mar 29, 2012
View
@@ -0,0 +1,4 @@
+source 'http://rubygems.org'
+
+gem 'perftools.rb', :git => 'git://github.com/bearded/perftools.rb.git', :branch => 'perftools-1.8'
+gem 'mixology'
View
@@ -0,0 +1,18 @@
+GIT
+ remote: git://github.com/bearded/perftools.rb.git
+ revision: df73f93e4dda8953e77ba3be2945f4bf806b07cf
+ branch: perftools-1.8
+ specs:
+ perftools.rb (0.5.6)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ mixology (0.2.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ mixology
+ perftools.rb!
View
@@ -0,0 +1,5 @@
+## DCI vs Include ##
+
+[Benchmarking DCI in Ruby](http://mikepackdev.com/blog_posts/22-benchmarking-dci-in-ruby)
+
+Mike Pack
View
@@ -0,0 +1,14 @@
+# Taken from Aaron Patterson's blog
+# http://tenderlovemaking.com/2011/06/29/i-want-dtrace-probes-in-ruby/
+
+module Allocation
+ def self.count
+ GC.disable
+ before = ObjectSpace.count_objects
+ yield
+ after = ObjectSpace.count_objects
+ after.each { |k,v| after[k] = v - before[k] }
+ GC.enable
+ after
+ end
+end
View
@@ -0,0 +1,16 @@
+require 'benchmark'
+require './runner'
+
+class DCIUser; end
+
+Benchmark.bm do |bench|
+ 3.times do
+ bench.report('DCI') do
+ 1000000.times do
+ user = DCIUser.new
+ user.extend Runner
+ user.run
+ end
+ end
+ end
+end
@@ -0,0 +1,17 @@
+require 'benchmark'
+require './runner'
+require 'mixology'
+
+class DCIUser; end
+
+Benchmark.bm do |bench|
+ 3.times do
+ bench.report('DCI') do
+ 1000000.times do
+ user = DCIUser.new
+ user.mixin Runner
+ user.run
+ end
+ end
+ end
+end
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,12 @@
+require 'perftools'
+require './runner'
+
+class DCIUser; end
+
+PerfTools::CpuProfiler.start('/tmp/dci_profile') do
+ 1000000.times do
+ user = DCIUser.new
+ user.extend Runner
+ user.run
+ end
+end
@@ -0,0 +1,13 @@
+require 'perftools'
+require './runner'
+require 'mixology'
+
+class DCIUser; end
+
+PerfTools::CpuProfiler.start('/tmp/dci_profile_mixology') do
+ 1000000.times do
+ user = DCIUser.new
+ user.mixin Runner
+ user.run
+ end
+end
View
@@ -0,0 +1,12 @@
+require './runner'
+require './allocation'
+
+class DCIUser; end
+
+p(Allocation.count do
+ 1000000.times do
+ user = DCIUser.new
+ user.extend Runner
+ user.run
+ end
+end)
@@ -0,0 +1,13 @@
+require './runner'
+require './allocation'
+require 'mixology'
+
+class DCIUser; end
+
+p(Allocation.count do
+ 1000000.times do
+ user = DCIUser.new
+ user.mixin Runner
+ user.run
+ end
+end)
View
@@ -0,0 +1,17 @@
+require 'benchmark'
+require './runner'
+
+class IncludeUser
+ include Runner
+end
+
+Benchmark.bm do |bench|
+ 3.times do
+ bench.report('include') do
+ 1000000.times do
+ user = IncludeUser.new
+ user.run
+ end
+ end
+ end
+end
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,13 @@
+require 'perftools'
+require './runner'
+
+class IncludeUser
+ include Runner
+end
+
+PerfTools::CpuProfiler.start('/tmp/include_profile') do
+ 1000000.times do
+ user = IncludeUser.new
+ user.run
+ end
+end
View
@@ -0,0 +1,13 @@
+require './runner'
+require './allocation'
+
+class IncludeUser
+ include Runner
+end
+
+p(Allocation.count do
+ 1000000.times do
+ user = IncludeUser.new
+ user.run
+ end
+end)
View
@@ -0,0 +1,13 @@
+module Runner
+ def self.included(base)
+ # p "Included into #{base.name}"
+ end
+
+ def self.extended(base)
+ # p "Extended into #{base.class.name}"
+ end
+
+ def run
+ Math.tan(Math::PI / 4)
+ end
+end

0 comments on commit 2d77b2f

Please sign in to comment.