Created
January 5, 2018 19:58
-
-
Save aks/e0032bbbbccdfcb0741f5e309beafffd to your computer and use it in GitHub Desktop.
Measure `match` vs `include` in rspecs on string tests
This file contains hidden or 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 'rails_helper' | |
| require 'benchmark' | |
| RSpec.describe 'testing match vs includes' do | |
| let(:subject) { "This is the time for all good men to come to the aid of their country" } | |
| HOW_MANY_TIMES = 100_000 | |
| Benchmark.bm(10) do |bm| | |
| bm.report("match:") do | |
| HOW_MANY_TIMES.times do |x| | |
| it { is_expected.to match "good" } | |
| end | |
| end | |
| bm.report("include:") do | |
| HOW_MANY_TIMES.times do |x| | |
| it { is_expected.to include "good" } | |
| end | |
| end | |
| end | |
| end |
This file contains hidden or 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
| $ be rspec spec/test_match_spec.rb | |
| user system total real | |
| match: 9.020000 1.000000 10.020000 ( 10.100684) | |
| include: 7.490000 0.940000 8.430000 ( 8.467608) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment