Compare Array#drop with Array#[]#181
Conversation
Endless ranges were introduced in Ruby 2.6, and are mentioned as a way to idiomatically slice arrays. (https://ruby-doc.org/core-2.6/Range.html#class-Range-label-Endless+Ranges) This is slower than using `Enumerable#drop`.
|
It is not, and it shouldn't be (otherwise it would be a bug and we'd optimize MRI). Move the range creation out of your block and you will get similar results. |
|
FYI: |
Thanks @marcandre! That makes a whole lot of sense, I hadn't considered that we're really doing two operations with the range creation and the array slicing. Just so we have the data, I confirmed that if the range construction happens elsewhere then the results of I'm still not sure how to go about this one. The pattern I've seen is to construct the range in the In any case, I agree that as it stands this is not really a comparison of
Ah yes, very true, thanks @mblumtritt! I'll rename this PR before closing to reflect that. |
Endless ranges were introduced in Ruby 2.6, and are mentioned as a way
to idiomatically slice arrays.
(https://ruby-doc.org/core-2.6/Range.html#class-Range-label-Endless+Ranges)
This is slower than using
Enumerable#drop.