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
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
Share on other sites

When I clocked it, the single line echo takes 2400ms and sending the same info with single echos each takes 350ms so im not seeing what you describe.

I'm using GoDaddy so have no control over the "setup" any thing I should ask them?

 

 

 

Link to comment
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
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
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
Share on other sites

you realize that there is a huge range of tolerance (about 1-5 seconds) on page loads because of internet influx if you aren't testing locally. I.E cahced data, name server response, local machine response, server response, etc etc. Especially if you on a shared server

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.