Thursday, 15 April 2010

optimization - Fastest way to compare numbers in php -



optimization - Fastest way to compare numbers in php -

i have loop needs run few 1000000 times; 10,967,700 precise. within it, doing checks including:

number 1 less number 2 number 1 less or equal number 3 number 4 greater number 5

i'm wondering if there optimization/tweaks can perform have these checks performed faster. or ridiculous questino?

according snippet suggest next changes:

use for-loop instead of foreach example:

$key = array_keys($ahash); $size = sizeof($key); ($i=0; $i<$size; $i++) $ahash[$key[$i]] .= "a";

this foreach-loop 4.7x slower. (see illustration @ end - http://www.phpbench.com/)

foreach($ahash $key=>$val) $ahash[$key] .= "a";

as checking value set empty()-method faster isset().

using if , elseif (using ===) faster (==)

i hope help you.

(performance source: http://www.phpbench.com/)

php optimization

No comments:

Post a Comment