3 ms·
Performance differences are anything but negligible. In the case of the "billion elements", you are now spending the majority of time for reversing the array tw
by revelation 14y ago
Performance differences are anything but negligible. In the case of the "billion elements", you are now spending the majority of time for reversing the array twice.
As a programmer you should always know what kind of cost you are incurring, both asymptotically and down to cycles.
Trying to condense all the cases into one (using reverse or local state like 'step' from OPs version) is what hurts readability and maintainability.
Also, the "buy more metal" argument is hardly applicable for implementing this one way or another. Its an argument for using whatever platform you are most productive in.
- sanderjd 14y ago> As a programmer you should always know what kind of cost you are incurring, both asymptotically and down to cycles. No, as a programmer, you should be able to determine what kind of cost you are incurring when it matters, and much more importantly, you should be able to determine when it matters and when it doesn't.
- tylermenezes 14y ago> usually And even in the case of a billion elements, the difference in time is still negligible. Developer time is almost always better to optimize for. There's a reason Facebook and Google weren't coded entirely in C.