Skip to content

Instantly share code, notes, and snippets.

@cbandy
Created May 2, 2012 20:31
Show Gist options
  • Select an option

  • Save cbandy/2580197 to your computer and use it in GitHub Desktop.

Select an option

Save cbandy/2580197 to your computer and use it in GitHub Desktop.
require 'benchmark'
require 'delegate'
class DecorateUser
end
class RunnerDecorator < DelegateClass(DecorateUser)
def initialize(user)
super user
end
def run
Math.tan(Math::PI / 4)
end
end
Benchmark.bm do |bench|
3.times do
bench.report('decorate') do
1000000.times do
user = RunnerDecorator.new(DecorateUser.new)
user.run
end
end
end
end
require 'benchmark'
class ExtendUser
end
module Runner
def run
Math.tan(Math::PI / 4)
end
end
Benchmark.bm do |bench|
3.times do
bench.report('extend') do
1000000.times do
user = ExtendUser.new
user.extend Runner
user.run
end
end
end
end
require 'benchmark'
module Runner
def run
Math.tan(Math::PI / 4)
end
end
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment