Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
1-loop vs. 2-loop
<?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;
<?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
You can’t perform that action at this time.