Brenden Frank Posted January 1, 2009 Share Posted January 1, 2009 Which is the best method or does it even matter? I know this example isn't very practical but I've seen times where I'd like to simply store all my outputs as a string then do one big final output at the end. However I could see if this string is getting big that this could cause overhead. Or would echo do about the same? $output = ""; for ($i=0;$i<50;$i++) //loop and create output string { $output .= "Something"; //gather everything into a string } echo $output; //output string or for ($i=0;$i<50;$i++) //loop and create output string { echo "Something"; //output the string as it comes } I like the output method because it allows me to very specifically monitor what is being outputted and is of course the most useful for functions with return values. Quote Link to comment Share on other sites More sharing options...
DarkSuperHero Posted January 1, 2009 Share Posted January 1, 2009 I like to put it into a variable if I'm doing something else to it, like double checking its contents or formatting.. using Zend profiles, both took about the same to run...averaging out at .12ms... Quote Link to comment Share on other sites More sharing options...
Brenden Frank Posted January 1, 2009 Author Share Posted January 1, 2009 Perfect, that's all I needed to know. Thank you very much. Quote Link to comment Share on other sites More sharing options...
DarkSuperHero Posted January 1, 2009 Share Posted January 1, 2009 <?php $output = ""; for ($i=0;$i<10000;$i++) //loop and create output string { $output .= "Something"; //gather everything into a string } echo $output; //output string this code took 10.362ms to run on avarage or <?php for ($i=0;$i<10000;$i++) //loop and create output string { echo "Something"; //output the string as it comes } this code took 11.45ms seconds to run on avarage used Zend Profiler for both...:-) this is probably a better comparison, Quote Link to comment Share on other sites More sharing options...
Brenden Frank Posted January 1, 2009 Author Share Posted January 1, 2009 Ah, perfect. It's even faster. 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.