Created
August 29, 2019 17:36
-
-
Save kirs/a8e6f8b5994658648323e33ad7af8b29 to your computer and use it in GitHub Desktop.
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
# frozen_string_literal: true | |
require 'benchmark/ips' | |
require 'securerandom' | |
str = "#{SecureRandom.alphanumeric(1000)} SUBSTR" | |
Benchmark.ips do |x| | |
x.config(:time => 5, :warmup => 2) | |
x.report("=~") do |t| | |
100.times do | |
str =~ /SUBSTR/ | |
end | |
end | |
x.report("match?") do |t| | |
100.times do | |
str.match? /SUBSTR/ | |
end | |
end | |
x.report("include?") do |t| | |
100.times do | |
str.include?("SUBSTR") | |
end | |
end | |
x.compare! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment