| 
	
 | 
 Posted by Thomas Mlynarczyk on 10/18/06 18:45 
Also sprach Sonnich: 
 
> So, which is faster: 
> 
>      for($j = 0;$j<count($array);$j++) 
> or 
> 
> $j = 0 
> while($j<count($array)) 
>  $j++; 
 
I don't think they make much difference. If the "direction" doesn't matter,  
the following is much (!) faster as count($array) is calculated only once  
and there's one expression less to evaluate: 
 
for ( $i = count( $array ); $i--; ) 
{ 
    // do useful stuff 
} 
 
OTOH, if the "useful stuff" takes a lot of time, the performance gain might  
turn out to be negligible in comparison. 
 
> Which is faster: 
> 
> if  .... else   ... 
> or: 
> if (true)   ... 
> if (false)  ... 
 
I think, "if...else" should be slightly faster as only one condition needs  
to be evaluated. 
 
Greetings, 
Thomas
 
  
Navigation:
[Reply to this message] 
 |