Why is i=i+1 faster than i++?

后端 未结 5 632
野性不改
野性不改 2021-01-13 09:04

Test this code in Flash:

var i:int = 0;
for (var j:int = 0; j < 5000000; j++)
{
    i=i+1;
}// use about 300ms.

i = 0;
for (var j:int = 0; j < 5000000         


        
5条回答
  •  暖寄归人
    2021-01-13 09:27

    ++ and -- operators were designed to resemble the assembly code for increment and decrement, but nowadays it shouldn't make much difference with advancement of compilers. See section increase and decrease

    It could be a change in implementation or a temporary regression in actionscript virtual machine.

提交回复
热议问题