note 84395 added to function.microtime
| From: | pascalxusPLEASENOSPAM at yahoo dot com | Date: | Sat, 12 Jul 2008 08:19:12 +0000 |
| Subject: | note 84395 added to function.microtime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-141420@lists.php.net to get a copy of this message | ||
I wanted to find out whether echo would be quicker in small chunks or one large chunk to test the
theory mentioned in the previous post. The following experiment shows that there is no significant
performance difference, in terms of execution time elapsed, between the two methods of using echo.
I ran two test cases, one with a string that is 100000 bytes long and another with a string length
of 1000000. The source code follows below.
<?php
function echobig($string, $bufferSize = 8192)
{
$splitString = str_split($string, $bufferSize);
foreach($splitString as $chunk)
echo $chunk;
}
global $dat;
$dat = "";
function testit()
{
global $dat;
$data = "";
for( $a = 0; $a <= 1000000; $a += 1 ) $data .= "a";
$u1= microtime(true);
echobig( $data );
$u2= microtime(true);
echo $data;
$u3= microtime(true);
$diff = $u2 - $u1;
$diff2= $u3 - $u2;
$dat .= "$diff2 $diff $u2 $u1\r\n";
}
$i = 0;
while( $i < 5 )
{
testit(); $i += 1;
}
global $dat;
$fp = fopen( "../Data/results.txt", "w" );
fwrite( $fp, $dat );
fclose( $fp );
?>
You can run the above experiment yourself or you can look at my test data. I got some test data
here: http://www.codesplunk.com/examples/echo.html
----
Server IP: 208.69.120.35
Probable Submitter: 64.81.242.62
----
Manual Page -- http://www.php.net/manual/en/function.microtime.php
Edit -- https://master.php.net/note/edit/84395
Del: integrated -- https://master.php.net/note/delete/84395/integrated
Del: useless -- https://master.php.net/note/delete/84395/useless
Del: bad code -- https://master.php.net/note/delete/84395/bad+code
Del: spam -- https://master.php.net/note/delete/84395/spam
Del: non-english -- https://master.php.net/note/delete/84395/non-english
Del: in docs -- https://master.php.net/note/delete/84395/in+docs
Del: other reasons-- https://master.php.net/note/delete/84395
Reject -- https://master.php.net/note/reject/84395
Search -- https://master.php.net/manage/user-notes.php