Which is faster? Comparison or assignment?

前端 未结 12 1210
抹茶落季
抹茶落季 2020-12-05 04:16

I\'m doing a bit of coding, where I have to write this sort of code:

if( array[i]==false )
    array[i]=true;

I wonder if it should be re-w

12条回答
  •  天命终不由人
    2020-12-05 04:54

    As others have noted, this is micro-optimization.

    (In politics or journalism, this is known as navel-gazing ;-)

    Is the program large enough to have more than a couple layers of function/method/subroutine calls?

    If so, it probably had some avoidable calls, and those can waste hundreds as much time as low-level inefficiencies.

    On the assumption that you have removed those (which few people do), then by all means run it 10^9 times under a stopwatch, and see which is faster.

提交回复
热议问题