Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ruby 1.8 + SimpleDelegator. extremly slow
require 'delegate'
require 'benchmark'
class User
end
class UserPresenter < SimpleDelegator
end
N = 10_000
Benchmark.bmbm do |x|
x.report("Without presenter") { N.times { User.new } }
x.report("With presenter") { N.times { UserPresenter.new(User.new) } }
end
# Ruby 1.8
# Rehearsal -----------------------------------------------------
# Without presenter 0.010000 0.000000 0.010000 ( 0.005536)
# With presenter 5.220000 0.000000 5.220000 ( 5.287774)
# -------------------------------------------- total: 5.230000sec
# user system total real
# Without presenter 0.010000 0.000000 0.010000 ( 0.004076)
# With presenter 5.210000 0.010000 5.220000 ( 5.283736)
# Ruby 1.9
# Rehearsal -----------------------------------------------------
# Without presenter 0.010000 0.000000 0.010000 ( 0.005000)
# With presenter 0.010000 0.000000 0.010000 ( 0.010731)
# -------------------------------------------- total: 0.020000sec
# user system total real
# Without presenter 0.000000 0.000000 0.000000 ( 0.003953)
# With presenter 0.010000 0.000000 0.010000 ( 0.010640)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment