<?php
/* How many times the code under test should run in each function */
define('LOOP',15);
function f1(&$md5) {
$path = NULL;
$yy = date('y');
$ab = substr($md5, 0, 2);
$cd = substr($md5, 2, 2);
for($i=0; $i<LOOP; ++$i) {
$path = 'some' . '/';
$path .= $yy . '/';
$path .= $ab . '/';
$path .= $cd . '/';
}
}
function f2(&$md5) {
$path = NULL;
$yy = date('y');
$ab = substr($md5, 0, 2);
$cd = substr($md5, 2, 2);
for($i=0; $i<LOOP; ++$i) {
$path = sprintf('%s/%s/%s/%s', 'some', $yy, $ab, $cd);
}
}
$md5 = md5(str_shuffle('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'));
$start = microtime(true);
f1($md5);
$stop = microtime(true);
$time1 = $stop - $start;
$start = microtime(true);
f2($md5);
$stop = microtime(true);
$time2 = $stop - $start;
echo $time1 . "\t"; echo $time2 . "\n";
preferences:
33.21 ms | 402 KiB | 5 Q