I’m not saying local variables are faster than global – just that they often are, so if it matters to you check before assuming you need to use the less desirable global variable in the name of efficiency. Local variables can also all use the same memory locations – very important on processors that have very little memory.
Your assumption that 2 * X is slower than X + X is based on the assumption that a multiply is slower than an add. I don’t know for the Pentium but that is not always the case. In the vast majority of expressions in your program you will never notice the difference anyway.
Your assumption that 2 * X is slower than X + X is based on the assumption that a multiply is slower than an add. I don’t know for the Pentium but that is not always the case. In the vast majority of expressions in your program you will never notice the difference anyway.