4 ms·
Absolutely. Moreover, many of these minor run time differences are bound to change from one Ruby version to another[1]. I would even consider it harmful to rem
by epidemian 11y ago
Absolutely. Moreover, many of these minor run time differences are bound to change from one Ruby version to another[1].
I would even consider it harmful to remember many of these numbers as some sort of practical knowledge. I've actually known cases where a programmer would use some extraneous idioms and when told about a more idiomatic solution it turned out that they knew there was a more idiomatic way of doing it, but they used the more obfuscated alternative because "it was more performant". But it turned out that that knowledge was obsolete (it only applied to an old VM version) or incomplete (it only applied in some very specific cases).
So, beware of "knowing" that `arr.last` is slower than `arr[-1]`. It might not be for too long[2].
[1]: I'm speaking about MRI versions here; of course all those measurements are off if you use JRuby, rbx or Opal.
[2]: It is useful to remember that `arr.bsearch` on sorted arrays is faster than `arr.find`. That probably won't change in the near future ;)