Skip to content

Commit

Permalink
Merge branch 'JoelJuliano/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
kristianmandrup committed Mar 29, 2012
2 parents a8c870a + 258f64f commit 2d77b2f
Show file tree
Hide file tree
Showing 16 changed files with 180 additions and 0 deletions.
4 changes: 4 additions & 0 deletions benchmark/Gemfile
@@ -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'
18 changes: 18 additions & 0 deletions benchmark/Gemfile.lock
@@ -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!
5 changes: 5 additions & 0 deletions benchmark/README.md
@@ -0,0 +1,5 @@
## DCI vs Include ##

[Benchmarking DCI in Ruby](http://mikepackdev.com/blog_posts/22-benchmarking-dci-in-ruby)

Mike Pack
14 changes: 14 additions & 0 deletions benchmark/allocation.rb
@@ -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
16 changes: 16 additions & 0 deletions benchmark/dci_bm.rb
@@ -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
17 changes: 17 additions & 0 deletions benchmark/dci_bm_mixology.rb
@@ -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
Binary file added benchmark/dci_profile.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions benchmark/dci_profile.rb
@@ -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
13 changes: 13 additions & 0 deletions benchmark/dci_profile_mixology.rb
@@ -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
12 changes: 12 additions & 0 deletions benchmark/dci_space.rb
@@ -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)
13 changes: 13 additions & 0 deletions benchmark/dci_space_mixology.rb
@@ -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)
17 changes: 17 additions & 0 deletions benchmark/include_bm.rb
@@ -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
Binary file added benchmark/include_profile.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions benchmark/include_profile.rb
@@ -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
13 changes: 13 additions & 0 deletions benchmark/include_space.rb
@@ -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)
13 changes: 13 additions & 0 deletions benchmark/runner.rb
@@ -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.