Created
February 20, 2012 22:11
-
-
Save tatey/1871840 to your computer and use it in GitHub Desktop.
Mocha VS MiniTest::Mock and SimpleDelegate VS SimpleMock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I couldn't get
Benchmark.bm
to work like that. As far as I could tell, the argument tobm
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.