Skip to content

Instantly share code, notes, and snippets.

@aks
Created January 5, 2018 19:58
Show Gist options
  • Select an option

  • Save aks/e0032bbbbccdfcb0741f5e309beafffd to your computer and use it in GitHub Desktop.

Select an option

Save aks/e0032bbbbccdfcb0741f5e309beafffd to your computer and use it in GitHub Desktop.
Measure `match` vs `include` in rspecs on string tests
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
$ 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