Skip to content

Instantly share code, notes, and snippets.

@tatey
Created February 6, 2012 22:30
Show Gist options
  • Select an option

  • Save tatey/1755458 to your computer and use it in GitHub Desktop.

Select an option

Save tatey/1755458 to your computer and use it in GitHub Desktop.
Mocha VS SimpleDelegate
user system total real
mocha: 0.000000 0.000000 0.000000 (0.000277)
simple_delegator: 0.000000 0.000000 0.000000 (0.000024)
require 'benchmark'
require 'delegate'
require 'mocha'
Benchmark.bm(10000) do |x|
x.report :mocha do
array = [1]
array.expects(:push).with(2).returns([1, 2])
array.push(2)
end
x.report :delegator do
array = [1]
mock = Class.new(SimpleDelegator) { def push(*args); [1, 2]; end }.new(array)
mock.push(2)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment