3 ms·
> Your concern 99% of the time when you are trying to think at this level is performance, and thinking in C will give you the right intuition about how many ins
by munificent 8y ago
> Your concern 99% of the time when you are trying to think at this level is performance, and thinking in C will give you the right intuition about how many instructions your code is generating
I really don't think that's true given modern optimizing compilers. I remember back when C "best practices" were:
* Avoid moving code out into separate functions since calls are expensive.
* Hoist subexpressions out of loops to avoid recomputing them.
* Cache things in memory to avoid recomputing them.
But inlining means now we refactor things into small functions and usually expect that to be free. Optimizers automatically hoist common subexpressions out of loops.
And caching is useful, but making your data structures larger can cause more data cache misses, which can be more expensive that just recomputing things. I've seen good CPU cache usage make a 50x difference in performance.
Even in C, optimizing is now an empirical art and not something you can reason about from first principles and running the compiler in your head.