3 ms·
It's generally true. Both Rust and C++ (and Swift to a smaller extent) are both all about the "zero cost abstractions", but they usually aren't. It's hard to be
by OskarS 5y ago
It's generally true. Both Rust and C++ (and Swift to a smaller extent) are both all about the "zero cost abstractions", but they usually aren't. It's hard to beat the C-style for-loop: they map really closely to the underlying hardware, and modern compilers are starting to become really good at auto-vectorizing them.
- nicoburns 5y agoThat's not a general rule. In Rust iterator chains are frequently faster than for loops, and are just as likely to be auto-vectorized (or not at the whim of the compiler) as for-loops.
- qayxc 5y ago> It's hard to beat the C-style for-loop: they map really closely to the underlying hardware, and modern compilers are starting to become really good at auto-vectorizing them. Except with many compilers and depending on the loop, for-loops may optimise much poorer than their C++/Rust iterator based counterparts. That's because modern language constructs can communicate intent much clearer to the compiler than a primitive for-loop can; the compiler has to make fewer assumptions (which can can be wrong). So no, it's not "generally true" at all.
- deleted 5y ago[deleted]
- Ar-Curunir 5y agoThat’s not necessarily true; sometimes the higher level abstractions can provide more information to the compiler