문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

Any good compiler should give you the same machine code for both expressions.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top