Skip to content

Commit

Permalink
Added benchmarks.
Browse files Browse the repository at this point in the history
Performance improvements.
  • Loading branch information
Brian Takita committed Jan 17, 2009
1 parent ddd7123 commit 4267b53
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 11 deletions.
32 changes: 32 additions & 0 deletions benchmarks/rr_benchmark.rb
@@ -0,0 +1,32 @@
dir = File.dirname(__FILE__)
require File.expand_path("#{dir}/../lib/rr")
require "benchmark"

o = Object.new

Benchmark.bm do |x|
x.report do
1000.times do
RR.mock(o).foobar.returns("baz")
o.foobar
RR.reset
end
end
end

#require "ruby-prof"
#RubyProf.start
#
##RR.mock(o).foobar.returns("baz")
##o.foobar
#250.times do
# RR.mock(o).foobar.returns("baz")
# o.foobar
# RR.reset
#end
#
#result = RubyProf.stop
#
## Print a flat profile to text
#printer = RubyProf::FlatPrinter.new(result)
#printer.print(STDOUT, 0)
14 changes: 14 additions & 0 deletions benchmarks/rspec_benchmark.rb
@@ -0,0 +1,14 @@
require "rubygems"
require "spec/mocks"
require "benchmark"

o = Object.new

Benchmark.bm do |x|
x.report do
1000.times do
o.should_receive(:foobar).and_return("baz")
o.foobar
end
end
end
18 changes: 12 additions & 6 deletions lib/rr/double_definitions/double_definition_creator_proxy.rb
@@ -1,6 +1,17 @@
module RR
module DoubleDefinitions
class DoubleDefinitionCreatorProxy
class << self
def blank_slate_methods
instance_methods.each do |m|
unless m =~ /^_/ || m.to_s == 'object_id' || m.to_s == "instance_eval" || m.to_s == 'respond_to?'
alias_method "__blank_slated_#{m}", m
undef_method m
end
end
end
end

def initialize(creator, &block) #:nodoc:
@creator = creator
class << self
Expand All @@ -12,12 +23,7 @@ def __apply_blank_slate?
@apply_blank_slate ||= false
end

instance_methods.each do |m|
unless m =~ /^_/ || m.to_s == 'object_id' || m.to_s == "instance_eval" || m.to_s == 'respond_to?'
alias_method "__blank_slated_#{m}", m
undef_method m
end
end
blank_slate_methods

def instance_eval
return_value = super
Expand Down
10 changes: 5 additions & 5 deletions lib/rr/expectations/argument_equality_expectation.rb
Expand Up @@ -8,17 +8,17 @@ def initialize(*expected_arguments)
end

def exact_match?(*arguments)
return false unless arguments.length == @expected_arguments.length
return false unless arguments.length == expected_arguments.length
arguments.each_with_index do |arg, index|
return false unless equality_match(@expected_arguments[index], arg)
return false unless equality_match(expected_arguments[index], arg)
end
true
end

def wildcard_match?(*arguments)
return false unless arguments.length == @expected_arguments.length
return false unless arguments.length == expected_arguments.length
arguments.each_with_index do |arg, index|
expected_argument = @expected_arguments[index]
expected_argument = expected_arguments[index]
if expected_argument.respond_to?(:wildcard_match?)
return false unless expected_argument.wildcard_match?(arg)
else
Expand All @@ -29,7 +29,7 @@ def wildcard_match?(*arguments)
end

def ==(other)
@expected_arguments == other.expected_arguments
expected_arguments == other.expected_arguments
end

protected
Expand Down

0 comments on commit 4267b53

Please sign in to comment.