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

后端 未结 5 627
野性不改
野性不改 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:26

    I suggest instead of i++; use ++i; Because it is faster than both you mentioned.

    Look at this good explanation: What is more efficient i++ or ++i?

提交回复
热议问题