Skip to content

Instantly share code, notes, and snippets.

@sandro
Forked from jamesgolick/gist:334347
Created March 17, 2010 19:43
Show Gist options
  • Save sandro/335639 to your computer and use it in GitHub Desktop.
Save sandro/335639 to your computer and use it in GitHub Desktop.
benchmark regexp matching
require 'bench_press'
extend BenchPress
reps 1000
measure "=~" do
"abcdefg" =~ /a/
end
measure "String#match" do
"abcdefg".match /a/
end

Regexp Matching

Date: 2010-03-17

System Information

Operating System:    Mac OS X 10.6.2 (10C540)
CPU:                 Intel Core 2 Duo 2.4 GHz
Processor Count:     2
Memory:              4 GB
Ruby version:        1.8.7 patchlevel 248

"=~" is up to 88% faster over 1000 repetitions

=~              0.00290203094482422 secs    Fastest
String#match    0.0257871150970459  secs    88% Slower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment