Created
July 9, 2020 10:46
-
-
Save januszm/b1a17923c6b5629a87dcc10e61289c57 to your computer and use it in GitHub Desktop.
Ruby quick benchmark
This file contains 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
# 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