Skip to content

Instantly share code, notes, and snippets.

@pocke
Created October 30, 2016 02:48
Show Gist options
  • Save pocke/4a9f3ea672de9366992cd881f52b432b to your computer and use it in GitHub Desktop.
Save pocke/4a9f3ea672de9366992cd881f52b432b to your computer and use it in GitHub Desktop.
require 'benchmark'
Benchmark.bm 10 do |x|
x.report('=~'){ 10000000.times{/a/ =~ 'a'; /b/ =~ 'a' }}
x.report('==='){ 10000000.times{/a/ === 'a'; /b/ === 'a' }}
x.report('match'){ 10000000.times{/a/.match('a'); /b/.match('a') }}
x.report('match?'){10000000.times{/a/.match?('a'); /b/.match?('a') }}
end
@pocke
Copy link
Author

pocke commented Oct 30, 2016

                 user     system      total        real
=~           5.040000   0.030000   5.070000 (  5.077508)
===          5.030000   0.000000   5.030000 (  5.033202)
match        5.840000   0.000000   5.840000 (  5.836059)
match?       1.670000   0.000000   1.670000 (  1.669442)

@pocke
Copy link
Author

pocke commented Oct 30, 2016

$ ruby -v
ruby 2.4.0preview2 (2016-09-09 trunk 56129) [x86_64-linux]

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