3 ms·
I know what that means to me (as a practical issue, as opposed to an internal mechanism issue), and I am sort of face-palming. I spent a great deal of time, le
by ChrisMarshallNY 5y ago
I know what that means to me (as a practical issue, as opposed to an internal mechanism issue), and I am sort of face-palming.
I spent a great deal of time, learning "idiomatic Swift" coding practices. I can do some damn clever HOF stuff (inlined maps and reduces).
This tells me that I may be better off, doing "classic C"-style coding, like I did, when I was just getting started with Swift.
Sigh...
- OskarS 5y agoIt'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
- simondotau 5y agoThis isn't the right lesson to derive from this. These benchmarks show that the high performance cores pack a lot of smarts which can maintain high performance with idomatic Swift. Idiomatic Swift is still great for code which doesn't have significant performance consequences and/or is likely to only ever run on the Firestorm cores—i.e. any user-interactive process. If you're writing a background task which is expected to have some non-negligible load on the CPU, it could make sense to experiment with simpler C-style coding for the hottest loops in your code.