- microtime: documentation ( source)
- define: documentation ( source)
- sprintf: documentation ( source)
<?php
/* How many times the code under test should run in each function */
define('LOOP',1000000);
function f1() {
$var = NULL;
for($i=0; $i<LOOP; ++$i) {
$var = 'abc';
$var .= ' some other thing ';
$var .= ' 123 : 456';
}
}
function f2() {
$var = NULL;
for($i=0; $i<LOOP; ++$i) {
$var = sprintf('%s%s %d : %d', 'abc', ' some other thing ', 123, 456);
}
}
$start = microtime(true);
f1();
$stop = microtime(true);
$time1 = $stop - $start;
$start = microtime(true);
f2();
$stop = microtime(true);
$time2 = $stop - $start;
echo $time1 . "\t";
echo $time2 . "\n";