Skip to content

Instantly share code, notes, and snippets.

@kingcrunch
Created August 17, 2011 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kingcrunch/1152564 to your computer and use it in GitHub Desktop.
Save kingcrunch/1152564 to your computer and use it in GitHub Desktop.
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