2 ms·
Ruby 2.4 adds a new #match? method for regular expressions which is three times faster than any Regexp method in Ruby 2.3: Why does Ruby have 4 different regex
by sergiotapia 10y ago
Ruby 2.4 adds a new #match? method for regular expressions which is three times faster than any Regexp method in Ruby 2.3:
Why does Ruby have 4 different regexp match functions?
Regexp#match?: 2630002.5 i/s
Regexp#===: 872217.5 i/s - 3.02x slower
Regexp#=~: 859713.0 i/s - 3.06x slower
Regexp#match: 539361.3 i/s - 4.88x slower
- Olap84 10y agoSo there is choice of course. match returns match data, and sets the $~ variable === returns true or false, setting the $~ variable =~ returns integer (position) or nil, setting $~ The newest one match? returns a boolean, not setting $~
- thelibrarian 10y agoAlso, === is the method used in case statement matching.