- microtime: documentation ( source)
- define: documentation ( source)
- printf: documentation ( source)
<?php
define('ITERATIONS', 10000000);
$start = microtime(true);
$var = 0;
while ($var < ITERATIONS) {
++$var;
}
$stop = microtime(true);
printf("Loop type %8s took %f seconds\n", 'while', $stop - $start);
$start = microtime(true);
$var = 0;
do {
++$var;
} while ($var < ITERATIONS);
$stop = microtime(true);
printf("Loop type %8s took %f seconds\n", 'do-while', $stop - $start);
$start = microtime(true);
for ($var = 0; $var < ITERATIONS; ++$var) {
//do nothing
}
$stop = microtime(true);
printf("Loop type %8s took %f seconds\n", 'for', $stop - $start);