chris h wrote:
Saeed here's a quick (and dirty) test I ran:
$tests = 1000000;
$start = microtime(true);
for ($i=0; $i<$tests; $i++) {
$a = md5( rand() );
$b = md5( rand() );
$c = $a.$b;
}
var_dump( "By concat op:\t". (microtime(true) - $start) );
that's not a fair test because you have rand() and md5() calls in there
(something temporally varying)
Here's a quick test script which does 100 million iterations on both, 3
times to get some half measurable results
$i = $its = 100000000;
$tests = 3;
$a = 'foo';
$b = 'bar';
while($tests-->0) {
$t = microtime(true);
while($i-->0) {
$c = "$a$b";
}
echo 'time .: ' . (microtime(true)-$t) . PHP_EOL;
$i = $its;
$t = microtime(true);
while($i-->0) {
$c = $a.$b;
}
echo 'time ": ' . (microtime(true)-$t) . PHP_EOL;
}
I also ran the tests in the opposite order just to ensure they were
fair, results are that $a.$b (concatenation) averaged 22 seconds, and
the "$a$b" approach was 28 seconds.
Thus, concatenation is faster - but you have to get up to circa 10
million+ uses per second to use it.
Best,
Nathan
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php