fastruby / fast-ruby

:dash: Writing Fast Ruby :heart_eyes: -- Collect Common Ruby idioms.
https://github.com/fastruby/fast-ruby
5.67k stars 376 forks source link

`String#match` vs `String#scan` #185

Open AlexWayfer opened 4 years ago

AlexWayfer commented 4 years ago

Hello.

These methods are pretty similar.

I've done some benchmarks and figured out that match is twice faster than scan.

I can try to make a PR, but not sure do we need for it here.

ParadoxV5 commented 4 years ago

Friendly reminder: String#match outputs a MatchData while String#scan outputs an Array.

AlexWayfer commented 4 years ago

Friendly reminder: String#match outputs a MatchData while String#scan outputs an Array.

Yes, but they're similar, but an outside code will be different for the same input data (String and Regexp). But the point of comparison of these approaches is they complete the similar goal.

mateusdeap commented 1 year ago

@AlexWayfer If you're still interested in this, feel free to open a PR. All you need to do is follow the guidelines in the CONTRIBUTING.md.