[try Beta version]
Not logged in

 
Any performance difference between +1 and +100000

Jun 7, 2010 at 1:57pm
Will there be any computer executive efficiency difference between adding a small number and a big number?
Jun 7, 2010 at 2:25pm
Nope.
Jun 7, 2010 at 8:05pm
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).

Jun 8, 2010 at 1:44pm
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 Jun 8, 2010 at 1:46pm
Jun 8, 2010 at 1:52pm
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.