3 ms·
Like anything, it depends. I frequently work on pieces of code cannot be optimized algorithmically and memory allocation is the bottleneck. A version which doe
by EpicEng 10y ago
Like anything, it depends. I frequently work on pieces of code cannot be optimized algorithmically and memory allocation is the bottleneck.
A version which doesn't allocate a new chunk of memory will always be faster.
- mattdeboard 10y agoI'm going to assume this bottlenecked-by-mem-alloc work isn't Ruby. The rule of thumb I personally go by is that if you're working in e.g. Ruby or Python it's better to favor immutability over mutability because mem alloc will almost never be the problem. I say this having worked on a Python (pypy) product where mem alloc WAS the bottleneck in a particular area. So I know it's not always true, but almost always. Probably preaching to the choir here :)
- EpicEng 10y agoI can't disagree with you there. In this context you're probably right 99% of the time