x += 1
is just syntactical short cut for x = x + 1
. AFAIK, No machine (CPU) level instruction set has an instruction to do x += 1
in a single atomic operation. The actual code executed by the CPU should be identical.
Are there any performance benefits when using x += 1 instead of x = x+1?
-
02-06-2022 - |
문제
I am confused whether or not it is advisable to use x += 1
or x = x+1
. I know that they both produce the same results. In practical terms, are there any performance gain when using x+=1
instead of x = x+1
? Will it make my program run faster?
해결책
다른 팁
Any good compiler should give you the same machine code for both expressions.
제휴하지 않습니다 StackOverflow