4 ms·
Runtime speed is, as noted, going to be similar, with the winner being determined by which compiler optimisations benefit your code the most. Yes you could als
by sievebrain 10y ago
Runtime speed is, as noted, going to be similar, with the winner being determined by which compiler optimisations benefit your code the most.
Yes you could also pre-allocate, but that's often more awkward than just allocating at the time of need, and besides, Java can turn heap allocations into not only stack allocations, but fully scalarise them (i.e. break down an allocation into a set of local variables and then delete any that are unused, move them around, etc).
- CyberDildonics 10y ago> Runtime speed is, as noted, going to be similar, with the winner being determined by which compiler optimizations benefit your code the most. This could not possibly be further from the truth. Getting rid of heap allocations can speed something up by ~7x. Cache locality can speed something up by 50x. Compiler optimizations do very little compared to accessing memory in a predictable way.
- imtringued 10y agoIndeed! In Java or dynamic langauges you are forced to always use a reference. Which means you'll get cache misses pretty much everywhere.