I know, that addition operation is more trivial than multiplication operation. But will there be any difference in execution time of 123456 * 3 and 123456 + 123456 + 123456?
How exactly works multiplication?
Do multiplication algorithms vary in different programming languages?
How multiplication looks on low-level (i.e. Assembler code)?
In x86 assembly language the addition and multiplication operations look like this:
ADD [operand1], [operand2]
where operand1 can be register, operand 2 can be register, constant or memory address
It takes from 1 to 7 clocks depending on processor model and operand2 type
MUL [operand] ;for unsigned multiplication
multiplies the content of the accumulator register (AL, AX, EAX) with operand, which can be a register or a memory address. And again, depending on the type of the operand and processor model, it takes 12-38 clocks
There’s also a version of MUL that does signed multiplication.
This is core assembly language, without modern SIMD extensions like SSE etc. The real speed, as mentioned above, depends on the compiler optimizations.
A smart compiler will most likely replace your 123456 + 123456 + 123456 with 3*123456