Skip to content

Instantly share code, notes, and snippets.

@aks
Created January 28, 2018 01:36
Show Gist options
  • Select an option

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

Select an option

Save aks/2f84a293b02164e5f88e31f5183236de to your computer and use it in GitHub Desktop.
Benchmarking rspec matchers "match" and "include"
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
@aks

aks commented Jan 28, 2018

Copy link
Copy Markdown
Author

The output:

$ be rspec spec/test_match_spec.rb
Running via Spring preloader in process 63180
Applying workarounds
                 user     system      total        real
match:      10.060000   1.540000  11.600000 ( 11.694110)
include:     9.120000   1.440000  10.560000 ( 10.620734)

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