Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepack committed Jan 17, 2012
0 parents commit 56eaab2
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'http://rubygems.org'

gem 'perftools.rb', :git => 'git://github.com/bearded/perftools.rb.git', :branch => 'perftools-1.8'
16 changes: 16 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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:

PLATFORMS
ruby

DEPENDENCIES
perftools.rb!
14 changes: 14 additions & 0 deletions allocation.rb
Original file line number Diff line number Diff line change
@@ -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 dci_bm.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions dci_profile.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions dci_space.rb
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 17 additions & 0 deletions include_bm.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions include_profile.rb
Original file line number Diff line number Diff line change
@@ -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 include_space.rb
Original file line number Diff line number Diff line change
@@ -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 runner.rb
Original file line number Diff line number Diff line change
@@ -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 56eaab2

Please sign in to comment.