Skip to content

Instantly share code, notes, and snippets.

@ik5
Created March 18, 2018 17:38
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 ik5/72972956961c2e01eb7a16d1536dda60 to your computer and use it in GitHub Desktop.
Save ik5/72972956961c2e01eb7a16d1536dda60 to your computer and use it in GitHub Desktop.
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
@ik5
Copy link
Author

ik5 commented Mar 18, 2018

                    user     system      total        real
start_with?     0.115529   0.000000   0.115529 (  0.116792)
regex           0.187361   0.000909   0.188270 (  0.189854)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment