Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
Short-circuiting in C
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="BGB, post: 4216623"] actually, as far as performance is concerned, simple computations are faster than a (mispredicted) jump over them often even on plain x86 (including with floating point, albeit with the partial exception of slow/complex operations like "sqrt()" or "sin()", or large/bulky calculations). so, in my experience it is often a little faster just to do math which works over the entire range, rather than having to add conditionals into the mix. granted, it depends some, as many algorithms are expressed better with conditionals, or need them, so it is not usually worthwhile to try to micro-optimize them out. this situation also causes "switch()" when using a jump table to be a surprisingly expensive operation, which can matter somewhat when using a switch with a decent number of cases in a tight loop (for a small number of cases, compilers will often optimize this by using a slightly faster if-else chain internally, due mostly to branch-predictor magic...). also, memory accesses are very fast when in-cache (almost as fast as with plain registers), and IME it means that having values in registers is not necessarily better performance-wise, since often trying to keep values in registers may lead to a larger total number of loads and stores (due to register spills, ...) so often it will make more sense to leave variables on-stack or similar. IME, there has also been little difference performance with between simple and complex memory addresses, as apparently the processor calculates complex memory addresses more or less for free. actually, the above also results in a possible optimization of calculating integer expressions like "x*4+y" using a "lea" instruction. or such... [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
Short-circuiting in C
Top