<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml";>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test for Tedd</title>
</head>
<body>
<?php

# Ok tedd, if you insist ..

$iterations = 20000;
$test_string = md5('test'); // a 32 character string
$test_array = array();
for ($i = 0; $i < $iterations; ++$i) $test_array[] = str_shuffle($test_string);
# <--------- Comma
ob_start();
$s_t = microtime(true);
foreach ($test_array as $array_value) {
        echo $test_string, $array_value;
}
$e_t = microtime(true);
ob_end_clean();
echo '<p>Comma took: <strong>'.(abs($e_t -
$s_t)*1000/$iterations).'</strong> milliseconds on average.</p>';
# <---------- Concatenation
ob_start();
$s_t = microtime(true);
foreach ($test_array as $array_value) {
        echo $test_string.$array_value;
}
$e_t = microtime(true);
ob_end_clean();
echo '<p>Concatenation: <strong>'.(abs($e_t -
$s_t)*1000/$iterations).'</strong> milliseconds on average.</p>';
# <---------- Interpolation
ob_start();
$s_t = microtime(true);
foreach ($test_array as $array_value) {
        echo "{$test_string}{$array_value}";
}
$e_t = microtime(true);
ob_end_clean();
echo '<p>Interpolation: <strong>'.(abs($e_t -
$s_t)*1000/$iterations).'</strong> milliseconds on average.</p>';
# <---------- HereDoc
ob_start();
$s_t = microtime(true);
foreach ($test_array as $array_value) {
           echo <<<TEST
                $test_string$array_value
TEST;
}
$e_t = microtime(true);
ob_end_clean();
echo '<p>Heredoc: <strong>'.(abs($e_t -
$s_t)*1000/$iterations).'</strong> milliseconds on average.</p>';
/*
I usually get results similar to these ones:

Comma took: 0.0191585 milliseconds on average.
Concatenation: 0.0195376 milliseconds on average.
Interpolation: 0.0279227 milliseconds on average.
Heredoc: 0.0247411 milliseconds on average.

*/
?>
</body>
</html>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to