-
-
Save adam12/303fccd3803beb15ca6239a1c8f9fbc2 to your computer and use it in GitHub Desktop.
Mocha VS MiniTest::Mock and SimpleDelegate VS SimpleMock VS RR
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/ips' | |
require 'delegate' | |
require 'mocha/api' | |
require 'simple_mock' | |
require 'rr' | |
include Mocha::API | |
extend RR::Adapters::RRMethods | |
array = [1] | |
Benchmark.ips do |x| | |
x.report 'mocha' do | |
new_array = array.dup | |
new_array.expects(:push).with(2).returns([1, 2]) | |
new_array.push(2) | |
end | |
x.report 'delegator' do | |
mock = Class.new(SimpleDelegator) { def push(*args); [1, 2]; end }.new(array) | |
mock.push(2) | |
end | |
x.report 'simple_mock' do | |
mock = SimpleMock.new(array).expect(:push, [1, 2], [2]) | |
mock.push(2) | |
end | |
x.report 'rr' do | |
new_array = array.dup | |
mock(new_array).push(2) { [1, 2] } | |
new_array.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
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16] | |
Warming up -------------------------------------- | |
mocha 99.000 i/100ms | |
delegator 12.483k i/100ms | |
simple_mock 5.741k i/100ms | |
rr 242.000 i/100ms | |
Calculating ------------------------------------- | |
mocha 315.303 (±16.2%) i/s - 1.584k in 5.143984s | |
delegator 145.488k (±11.1%) i/s - 724.014k in 5.031831s | |
simple_mock 61.882k (± 8.9%) i/s - 310.014k in 5.046684s | |
rr 2.507k (±15.4%) i/s - 12.342k in 5.082613s |
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
# frozen_string_literal: true | |
source "https://rubygems.org" | |
gem "benchmark-ips" | |
gem "rr" | |
gem "mocha" | |
gem "simple_mock" |
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
GEM | |
remote: https://rubygems.org/ | |
specs: | |
benchmark-ips (2.7.2) | |
metaclass (0.0.4) | |
mocha (1.2.1) | |
metaclass (~> 0.0.1) | |
rr (1.2.0) | |
simple_mock (0.0.2) | |
PLATFORMS | |
ruby | |
DEPENDENCIES | |
benchmark-ips | |
mocha | |
rr | |
simple_mock | |
BUNDLED WITH | |
1.15.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment