Skip to content

Instantly share code, notes, and snippets.

@januszm
Created July 9, 2020 10:46
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 januszm/b1a17923c6b5629a87dcc10e61289c57 to your computer and use it in GitHub Desktop.
Save januszm/b1a17923c6b5629a87dcc10e61289c57 to your computer and use it in GitHub Desktop.
Ruby quick benchmark
# alternatively use benchmark/ips
n = 100_000
data = "..."
Benchmark.ips do |benchmark|
benchmark.report("include?") do
n.times { data.to_s.downcase.include?('windows') }
end
benchmark.report("match?") do
n.times { %r{[W|w]indows}.match?(data) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment