Skip to content

Instantly share code, notes, and snippets.

@tatey
Created February 20, 2012 22:11
Show Gist options
  • Save tatey/1871840 to your computer and use it in GitHub Desktop.
Save tatey/1871840 to your computer and use it in GitHub Desktop.
Mocha VS MiniTest::Mock and SimpleDelegate VS SimpleMock
require 'benchmark'
require 'delegate'
require 'mocha'
require 'simple_mock'
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
x.report :simple_mock do
array = [1]
mock = SimpleMock.new(array).expect(:push, [1, 2], [2])
mock.push(2)
end
end
user system total real
mocha: 0.000000 0.000000 0.000000 (0.000279)
simple_delegator: 0.000000 0.000000 0.000000 (0.000029)
simple_mock: 0.000000 0.000000 0.000000 (0.000057)
@chadoh
Copy link

chadoh commented May 15, 2012

I couldn't get Benchmark.bm to work like that. As far as I could tell, the argument to bm is the label width. It no effect in getting the tests to run multiple times for me. See my fork to see what did work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment