Jump to content

Verify Speed of echo


Hodo

Recommended Posts

Can someone verify the speed difference here with the echo statement.

 

I have 8 elements to send. I thought it would be more effiecient to send them in a single echo statement like this:

echo("LIST ".$rc.$spc.$row[0].$spc.$row[1].$spc.$row[2].$spc.$row[3].$spc.$row[4].$spc.$row[5].$spc.$btime.$spc.$row[8].$nl);

 

I tested sending each element in a single echo and it seems to be much faster.

 

Is it a speed problem with the php engine to concantenate the string to send a single echo?

Link to comment
https://forums.phpfreaks.com/topic/58711-verify-speed-of-echo/
Share on other sites

It is more efficient to send a single echo because than the parser does not have to essentially run "twice" to display the data.

 

So yea, one statement would be much more efficient than 2 statements. But it really should not matter for such a low number, where it would matter if you are spitting out 50,000 echo statements that could be done in 10,000 than you see a difference in speed. Either way it would be less than a second difference.

 

If you are seeing dramatic speed issues chances are it could be something wrong with the php setup of the server.

Link to comment
https://forums.phpfreaks.com/topic/58711-verify-speed-of-echo/#findComment-291199
Share on other sites

When I clocked it, the single line echo takes 2400ms ...

 

Almost two and a half seconds? WOW!! If that includes internet delivery times, you have a very very busy/slow connection. If that's the total execution time on the server for a one-line script you need new hosting.

 

 

Link to comment
https://forums.phpfreaks.com/topic/58711-verify-speed-of-echo/#findComment-292070
Share on other sites

From my benchmark, the concatenated result is almost twice as fast (taking less than an hour to print 8 items) as printing individual elements

 

<?php
$row = range(1,;

$t1 = microtime(1);

foreach ($row as $val) echo $val,' ';
echo '<br>';

$t2 = microtime(1);

echo join(' ', $row), '<br>';

$t3 = microtime(1);

printf ("Individual: %0.8f<br>Joined: %0.8f<br>Ratio: %0.2f", $t2-$t1, $t3-$t2, ($t2-$t1)/($t3-$t2));
?>

 

Result:

[pre]

1 2 3 4 5 6 7 8

1 2 3 4 5 6 7 8

Individual: 0.00011992

Joined: 0.00006604

Ratio: 1.82

[/pre]

Link to comment
https://forums.phpfreaks.com/topic/58711-verify-speed-of-echo/#findComment-292102
Share on other sites

Yes it does include internet times. I am calling the function from a c++ winsock on my computer and I do the timeing in c++. I send a code to the php file and it sends me the info. Same code 2 different delivery methods the single line was much slower.

I'll have to assume you all are correct in this matter since im a noob at php and you didn't see anything wrong with the way I coded it. Thanks mucho for your time.

Link to comment
https://forums.phpfreaks.com/topic/58711-verify-speed-of-echo/#findComment-292673
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.