You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This test is biased in favor of reverse each because it bails on the first element, 100. A fairer test would be to search for (x % 51).zero?, since we expect to traverse about half the elements on average.
I'd propose replacing reverse.detect with reverse_each.detect in the comparison, rather than adding it as a third option, for all the reasons listed in the reverse.each vs reverse_each section.
If there's support behind this, I'm happy to whip up a PR for it!
Yes, reverse_each.detect and reverse_each.any? are going to be more performant than select.last or reverse.detect.
This is even documented in another benchmark on the same page. But reference material by definition usually means you look at the one relevant entry.
Activity
PeterCamilleri commentedon Feb 11, 2016
This test is biased in favor of reverse each because it bails on the first element, 100. A fairer test would be to search for (x % 51).zero?, since we expect to traverse about half the elements on average.
nerdrew commentedon Feb 12, 2016
Results with
x % 51PeterCamilleri commentedon Feb 12, 2016
Wow. That sure seems to level the playing field.
parkerfinch commentedon Apr 11, 2018
I'd propose replacing
reverse.detectwithreverse_each.detectin the comparison, rather than adding it as a third option, for all the reasons listed in the reverse.each vs reverse_each section.If there's support behind this, I'm happy to whip up a PR for it!
corsonknowles commentedon Sep 21, 2020
Yes,
reverse_each.detectandreverse_each.any?are going to be more performant thanselect.lastorreverse.detect.This is even documented in another benchmark on the same page. But reference material by definition usually means you look at the one relevant entry.
It's worth an update!