Created
August 17, 2011 20:43
-
-
Save kingcrunch/1152564 to your computer and use it in GitHub Desktop.
1-loop vs. 2-loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$array = array(); | |
$c = 1000000; | |
for ($i = 0; $i <= $c; $i++) { | |
$array[] = $i; | |
} | |
$time = microtime(true); | |
for ($i = 0; $i <= $c; $i++) { | |
$array[$i] = $array[$i] * $array[$i]; | |
$array[$i] = base_convert($array[$i], 10, 16); | |
} | |
echo microtime(true) - $time; | |
echo PHP_EOL; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$array = array(); | |
$c = 1000000; | |
for ($i = 0; $i <= $c; $i++) { | |
$array[] = $i; | |
} | |
$time = microtime(true); | |
for ($i = 0; $i <= $c; $i++) { | |
$array[$i] = $array[$i] * $array[$i]; | |
} | |
for ($i = 0; $i <= $c; $i++) { | |
$array[$i] = base_convert($array[$i], 10, 16); | |
} | |
echo microtime(true) - $time; | |
echo PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment