Hacker News new | ask | show | jobs
by Cthulhu_ 1670 days ago
Plus they may have hidden performance costs - or benefits. They may have function invocation and memory layout costs, but they may also be parallelised and optimized transparently. A regular for-loop is super efficient in terms of memory layout / access but it's by definition singlethreaded.
1 comments

Yes, as always, it depends. The typical problem with array operations, e.g. in Fortran, is how well they're "scalarized", and the possible cost of not doing copy elimination over subroutine calls, for instance.

Presumably the exact semantics of a for-type loop depends on the language, but surely the C standard doesn't prevent auto-parallelization (including with SIMD vectorization, modulo arithmetic rules). Loops might also have OpenMP or other annotation.