note 71062 deleted from language.operators.string by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 15:17:31 +0000 |
| Subject: | note 71062 deleted from language.operators.string by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189844@lists.php.net to get a copy of this message | ||
Note Submitter: kevin at metalaxe dot com
----
I ran the follow script and found that using "$var" was 'mostly' slower than
using ' '.$var
<?php
$var = 1;
for( $x=0; $x < 101; $x++ )
{
echo '<br /><br />var = int( '.$var.' )<br />';
$timer->reset();
for( $i=0; $i<100001; $i++ )
{
$string = " {$var} {$var} {$var} {$var} {$var} {$var} {$var} {$var} {$var} {$var} {$var}
{$var} {$var} {$var} {$var}";
unset( $string );
}
echo 'One string with 15 $vars was set using one concat 100000 times and took
'.$timer->fetch_time().' seconds to execute <br />';
$timer->reset();
for( $i=0; $i<100001; $i++ )
{
$string = ' '.$var.' '.$var.' '.$var.' '.$var.'
'.$var.' '.$var.' '.$var.' '.$var.' '.$var.'
'.$var.' '.$var.' '.$var.' '.$var.' '.$var.'
'.$var;
unset( $string );
}
echo 'One string with 15 instances of $var was set using multiple concats 100000 times and
took '.$timer->fetch_time().' seconds to execute';
}
exit();
?>
Replacing $timer with a generic timing class of course.