Any performance difference between +1 and +100000

Will there be any computer executive efficiency difference between adding a small number and a big number?
Nope.
Note that incrementing (decrementing) by one can be very very very very very slightly faster if the
processor supports an INC/DEC instruction (such as Intel processors).

Some CPUs can be faster when adding small numbers because there is effectively an instruction for it already. A larger number has to be read from memory.

e.g (fabricated example) for a 16bit instruction. the first 10bits holds the actual instruction itself, the next 4 identify a register and the remaining 2 bits can hold the value to be added.

for a larger number:

the first 10bits holds the actual instruction, the next 4 identify the register, then a read from memory takes place to get the actualy number to be added.
Last edited on
Some CPUs can be faster when adding small numbers because there is effectively an instruction for it already. A larger number has to be read from memory.

What kind of CPUs would that be? Not counting inc instructions.

Even the inc instruction is not necessarily faster. When optimizing for recent Intel CPUs, GCC will actually use the add instruction instead of inc, even though this results in larger code.
Topic archived. No new replies allowed.