Hodo Posted July 6, 2007 Share Posted July 6, 2007 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? Quote Link to comment Share on other sites More sharing options...
per1os Posted July 6, 2007 Share Posted July 6, 2007 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. Quote Link to comment Share on other sites More sharing options...
Hodo Posted July 7, 2007 Author Share Posted July 7, 2007 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? Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 7, 2007 Share Posted July 7, 2007 Is there any real need to worry about the speed of using echo to display data? Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 7, 2007 Share Posted July 7, 2007 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. Quote Link to comment Share on other sites More sharing options...
Barand Posted July 7, 2007 Share Posted July 7, 2007 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] Quote Link to comment Share on other sites More sharing options...
Hodo Posted July 8, 2007 Author Share Posted July 8, 2007 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. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 8, 2007 Share Posted July 8, 2007 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.