Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions benchmarks/delegate_v_defined.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
require 'benchmark'
require 'delegate'

class Original

def my_method
true
end

end

class Delegated < DelegateClass(Original)
def initialize
super(Original.new)
end
end

class Composed
def initialize
@original = Original.new
end

define_method(:my_method) { @original.my_method }
end

n = 100_000

Benchmark.benchmark do |bm|
puts "#{n} times - ruby #{RUBY_VERSION}"

puts "[control] straight to obj"
bm.report do
n.times do
Original.new.my_method
end
end

puts "[delegate] DelegateClass to obj"
bm.report do
n.times do
Delegated.new.my_method
end
end

puts "[composed] passed to obj"
bm.report do
n.times do
Composed.new.my_method
end
end

end

# 100000 times - ruby 2.0.0
# [control] straight to obj
# 0.040000 0.000000 0.040000 ( 0.038468)
# [delegate] DelegateClass to obj
# 0.230000 0.000000 0.230000 ( 0.234356)
# [composed] passed to obj
# 0.070000 0.000000 0.070000 ( 0.071021)
2 changes: 1 addition & 1 deletion lib/rspec/core/example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def self.set_it_up(*args)
symbol_description = args.shift if args.first.is_a?(Symbol)
args << build_metadata_hash_from(args)
args.unshift(symbol_description) if symbol_description
@metadata = RSpec::Core::Metadata.new(superclass_metadata).process(*args)
@metadata = RSpec::Core::Metadata.new_for_example_group(superclass_metadata, *args)
hooks.register_globals(self, RSpec.configuration.hooks)
world.configure_group(self)
end
Expand Down
Loading