Skip to content

Instantly share code, notes, and snippets.

@kirs
Created August 29, 2019 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirs/a8e6f8b5994658648323e33ad7af8b29 to your computer and use it in GitHub Desktop.
Save kirs/a8e6f8b5994658648323e33ad7af8b29 to your computer and use it in GitHub Desktop.
# 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