Created
March 18, 2018 17:38
-
-
Save ik5/72972956961c2e01eb7a16d1536dda60 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
require 'benchmark' | |
N = 1_000_000 | |
REGEX = /^abc/ | |
STR = 'abc are letters'.freeze | |
Benchmark.bm(13) do |x| | |
x.report('start_with?') do | |
N.times do | |
STR.start_with?('abc') | |
end | |
end | |
x.report('regex') do | |
N.times do | |
STR =~ REGEX | |
end | |
end | |
end |
Author
ik5
commented
Mar 18, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment