New answers tagged

0

At a fundamental level, code that creates new copies of objects is going to require at least as many instructions as code that modifies existing objects, so it will generally not be faster in absolute terms. The exception is parallel algorithms where lock contention can make some amount of copying desirable. In the best case (as in your example), an ...


4

It would be misleading to make a general statement about such performance comparison: it simply depends on too many factors. Moreover, modern optimisers are really good at analysing the flow of execution. As a preliminary remark, functional style does not necessarily mean better performance. Without optimizers, a recursive version of a function may be ...


7

Modern high-performance garbage collectors are built on the assumption that most objects die young, and most objects are never mutated. Your functional version fits into that assumption: the objects are never mutated, and they can be collected after just one line. Most modern high-performance garbage collectors will not do any heap allocation for the code ...


Top 50 recent answers are included