Re: [PHP] Re: optimilize web page loading
Robert Cummings írta: On Sat, 2008-03-29 at 10:16 +0100, Zoltán Németh wrote: One last thing though... even if this were escaped and even if there were fifty variables embedded, a good bytecode optimizer (not quite the same as a bytecode cacher) would optimize the bytecode for caching so that the string is broken up according to what needs to be interpolated and what does not. could you tell me more about this bytecode optimizer stuff? how does it work, how much better/faster is it then APC/EAccelerator/etc? It really depends on what an optimizer optimizes. TurckMMCache had.has an optimizer. Zend offers an optimizer too. Optimizer can work in a number of ways. They may be an explicit part of the bytecode cache mechanism or possibly plugged as one element in a chain of bytecode processors... parser - optmizer - cacher. I'm not exactly sure how it works for PHP. The main difference between a cacher and an optimizer though is that generally speaking a caher only deals with caching the bytecode. No processing occurs on the produced bytecode. On the other hand an optimizer may perform alterates on the bytecodes to enhance speed. For example... by now most people on the list probably know that: ++$i; Is faster than: $i++; An optmizer might see $i++ and determine that the return value is not used and thus the operation can be changed from $i++ to ++$i. Smilarly, the optimizer might encounter the following expression: $foo = 1 8 And reduce the constant expression (1 8) to (256). So the expression essentially becomes: $foo = 256 Similarly if you take the following expression: $text = There was an old man from Nantuckit\n .Who's sole possession was a bucket.\n .One day with a grin,\n .While scratching his chin\n .He thought, \I think I'll build a rocket.\\n; This could be optimized by removing concatenation operations and producing a single unified string within the bytecode. These are just basic optimizations obviously. Optimization is not a new thing, if you've ever used the -O flags when building a C program then you know that C compilers can also perform optimizations. Cheers, Rob. thanks, I get the concept greets, Zoltán Németh -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
2008. 03. 28, péntek keltezéssel 10.59-kor Robert Cummings ezt írta: On Fri, 2008-03-28 at 15:30 +0100, Zoltán Németh wrote: 2008. 03. 28, péntek keltezéssel 10.24-kor Robert Cummings ezt írta: On Fri, 2008-03-28 at 14:46 +0100, Zoltán Németh wrote: yeah maybe. you're right, the bytecode is the same. but somewhere I heard that the parsing is the same too - because escaped characters can be in any string, though I'm not that sure about this anymore, as my link proved something else ;) Single quoted strings do support some escape characters. As far as I know only you can only escape a single quote and a backslash when creating a string via single quotes. yes, but I think the parser would still need to tokenize the string and verify each token whether it contains an escape character or not - which should be the same process as tokenizing and checking for escape character and $ signs. Nope, when processing a single quoted string there should be 4 available parse branches: EOF '(end of string) \ EOF \ ' anything else anything else Whereas with a double quoted string you have something along the lines of: EOF (end of string) $(begin variable) {(possible begin interpolation) $(begin interpolation) \ EOF \ ' t n r x v f digit anything else anything else So presuming no variable is embeded and assuming no escaped characters... double quotes still need to check for the beginning of variable interpolation which has 2 different start possibilities. With respect to creating the byte code single quotes have 4 branches, double quotes have 6 branches in the simplest of cases with no escape and no interpolation. So one would expect compile time for double quotes to be approximately 33% slower than for single quotes. good points, thanks for the detailed info (not that I'd focus on it while coding but its sooo interesting :) ) Once compiled though, the point is moot especially since most sites use a bytecode cache like eAccelerator or APC. Even without a cache htough, the time difference is tncy, and this is just for informational purposes :) There are usually bigger eggs to fry when optimizing. sure, these questions like 'echo or print' and 'single or double quotes' and 'for or while' and so on should never be mentioned when talking about real life code optimizing, as the difference they may make is so minimal. talking about these is good only for satisfying some of my (and maybe some other people's) curiosity about how php works internally :) One last thing though... even if this were escaped and even if there were fifty variables embedded, a good bytecode optimizer (not quite the same as a bytecode cacher) would optimize the bytecode for caching so that the string is broken up according to what needs to be interpolated and what does not. could you tell me more about this bytecode optimizer stuff? how does it work, how much better/faster is it then APC/EAccelerator/etc? greets, Zoltán Németh Cheers, Rob. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
2008. 03. 28, péntek keltezéssel 11.31-kor tedd ezt írta: At 9:14 AM +0100 3/28/08, Zoltán Németh wrote: This way for literal strings, the PHP parser doesn't have to evaluate this string to determine if anything needs to be translated (e.g., $report .= I like to $foo). A minimal speedup, but nonetheless... that above statement is simply not true. parsing foo and 'foo' is all the same a good read about it: http://blog.libssh2.org/index.php?/archives/28-How-long-is-a-piece-of-string.html greets, Zoltán Németh I read it, but it still doesn't disprove the premise. yeah, that was morning time and I got mixed up a bit :) Anyway, I had to admit that I was wrong in this matter, Rob Cummings has just proven me that there is a difference, however little is it greets, Zoltán Németh Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
On Sat, 2008-03-29 at 10:16 +0100, Zoltán Németh wrote: One last thing though... even if this were escaped and even if there were fifty variables embedded, a good bytecode optimizer (not quite the same as a bytecode cacher) would optimize the bytecode for caching so that the string is broken up according to what needs to be interpolated and what does not. could you tell me more about this bytecode optimizer stuff? how does it work, how much better/faster is it then APC/EAccelerator/etc? It really depends on what an optimizer optimizes. TurckMMCache had.has an optimizer. Zend offers an optimizer too. Optimizer can work in a number of ways. They may be an explicit part of the bytecode cache mechanism or possibly plugged as one element in a chain of bytecode processors... parser - optmizer - cacher. I'm not exactly sure how it works for PHP. The main difference between a cacher and an optimizer though is that generally speaking a caher only deals with caching the bytecode. No processing occurs on the produced bytecode. On the other hand an optimizer may perform alterates on the bytecodes to enhance speed. For example... by now most people on the list probably know that: ++$i; Is faster than: $i++; An optmizer might see $i++ and determine that the return value is not used and thus the operation can be changed from $i++ to ++$i. Smilarly, the optimizer might encounter the following expression: $foo = 1 8 And reduce the constant expression (1 8) to (256). So the expression essentially becomes: $foo = 256 Similarly if you take the following expression: $text = There was an old man from Nantuckit\n .Who's sole possession was a bucket.\n .One day with a grin,\n .While scratching his chin\n .He thought, \I think I'll build a rocket.\\n; This could be optimized by removing concatenation operations and producing a single unified string within the bytecode. These are just basic optimizations obviously. Optimization is not a new thing, if you've ever used the -O flags when building a C program then you know that C compilers can also perform optimizations. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
2008. 03. 27, csütörtök keltezéssel 11.13-kor Jason Pruim ezt írta: On Mar 27, 2008, at 11:05 AM, Shawn McKenzie wrote: Al wrote: Good point. I usually do use the single quotes, just happened to key doubles for the email. Actually, it's good idea for all variable assignments. Philip Thompson wrote: On Mar 26, 2008, at 6:28 PM, Al wrote: Depends on the server and it's load. I've strung together some rather large html strings and they aways take far less time than the transient time on the internet. I used to use OB extensively until one day I took the time to measure the difference. I don't recall the numbers; but, I do recall it was not worth the slight extra trouble to use OB. Now, I simple assemble by html strings with $report .= foo; And then echo $report at the end. It also makes the code very easy to read and follow. You might as well take it a step further. Change the above to: $report .= 'foo'; This way for literal strings, the PHP parser doesn't have to evaluate this string to determine if anything needs to be translated (e.g., $report .= I like to $foo). A minimal speedup, but nonetheless... ~Philip Andrew Ballard wrote: On Wed, Mar 26, 2008 at 1:18 PM, Al [EMAIL PROTECTED] wrote: You are really asking an HTML question, if you think about it. At the PHP level, either use output buffering or assemble all your html string as a variable and then echo it. The goal is to compress the string into the minimum number of packets. Yes, but do so smartly. Excessive string concatenation can slow things down as well. On most pages you probably won't notice much difference, but I have seen instances where the difference was painfully obvious. Andrew Yes and if your script takes .0002 seconds to run using double quotes it will only take .00019 seconds with single (depending upon how many quotes you have of course) :-) I'm coming in late to this thread so sorry if I missed this :) How much of a difference would it make if you have something like this: echo $foo bar bar bar bar $foo $foo; verses: echo $foo . bar bar bar bar . $foo $foo; ?In other words... You have a large application which is most likely to be faster? :) if you have variables in the mix, concatenation is better than interpolation greets, Zoltán Németh -Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424-9337 www.raoset.com [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
2008. 03. 27, csütörtök keltezéssel 10.21-kor Shawn McKenzie ezt írta: Jason Pruim wrote: On Mar 27, 2008, at 11:05 AM, Shawn McKenzie wrote: Al wrote: Good point. I usually do use the single quotes, just happened to key doubles for the email. Actually, it's good idea for all variable assignments. Philip Thompson wrote: On Mar 26, 2008, at 6:28 PM, Al wrote: Depends on the server and it's load. I've strung together some rather large html strings and they aways take far less time than the transient time on the internet. I used to use OB extensively until one day I took the time to measure the difference. I don't recall the numbers; but, I do recall it was not worth the slight extra trouble to use OB. Now, I simple assemble by html strings with $report .= foo; And then echo $report at the end. It also makes the code very easy to read and follow. You might as well take it a step further. Change the above to: $report .= 'foo'; This way for literal strings, the PHP parser doesn't have to evaluate this string to determine if anything needs to be translated (e.g., $report .= I like to $foo). A minimal speedup, but nonetheless... ~Philip Andrew Ballard wrote: On Wed, Mar 26, 2008 at 1:18 PM, Al [EMAIL PROTECTED] wrote: You are really asking an HTML question, if you think about it. At the PHP level, either use output buffering or assemble all your html string as a variable and then echo it. The goal is to compress the string into the minimum number of packets. Yes, but do so smartly. Excessive string concatenation can slow things down as well. On most pages you probably won't notice much difference, but I have seen instances where the difference was painfully obvious. Andrew Yes and if your script takes .0002 seconds to run using double quotes it will only take .00019 seconds with single (depending upon how many quotes you have of course) :-) I'm coming in late to this thread so sorry if I missed this :) How much of a difference would it make if you have something like this: echo $foo bar bar bar bar $foo $foo; verses: echo $foo . bar bar bar bar . $foo $foo; ?In other words... You have a large application which is most likely to be faster? :) nope. it parses both, since you may have escaped characters within single quotes too. so the difference only comes in when you actually have a variable in the string. greets, Zoltán Németh -Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424-9337 www.raoset.com [EMAIL PROTECTED] I would assume your 2 examples to be the same because the point is that the PHP interpreter must parse for vars to substitute when it encounters double-quotes whether there are any vars in it or not. With single-quotes the interpreter does not have to worry about it. Regardless, the speed diff is probably negligible, hence my flame inviting post. :-) -Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
2008. 03. 27, csütörtök keltezéssel 09.29-kor Philip Thompson ezt írta: On Mar 26, 2008, at 6:28 PM, Al wrote: Depends on the server and it's load. I've strung together some rather large html strings and they aways take far less time than the transient time on the internet. I used to use OB extensively until one day I took the time to measure the difference. I don't recall the numbers; but, I do recall it was not worth the slight extra trouble to use OB. Now, I simple assemble by html strings with $report .= foo; And then echo $report at the end. It also makes the code very easy to read and follow. You might as well take it a step further. Change the above to: $report .= 'foo'; This way for literal strings, the PHP parser doesn't have to evaluate this string to determine if anything needs to be translated (e.g., $report .= I like to $foo). A minimal speedup, but nonetheless... that above statement is simply not true. parsing foo and 'foo' is all the same a good read about it: http://blog.libssh2.org/index.php?/archives/28-How-long-is-a-piece-of-string.html greets, Zoltán Németh ~Philip Andrew Ballard wrote: On Wed, Mar 26, 2008 at 1:18 PM, Al [EMAIL PROTECTED] wrote: You are really asking an HTML question, if you think about it. At the PHP level, either use output buffering or assemble all your html string as a variable and then echo it. The goal is to compress the string into the minimum number of packets. Yes, but do so smartly. Excessive string concatenation can slow things down as well. On most pages you probably won't notice much difference, but I have seen instances where the difference was painfully obvious. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
2008. 03. 28, péntek keltezéssel 09.19-kor Zoltán Németh ezt írta: 2008. 03. 27, csütörtök keltezéssel 10.21-kor Shawn McKenzie ezt írta: Jason Pruim wrote: On Mar 27, 2008, at 11:05 AM, Shawn McKenzie wrote: Al wrote: Good point. I usually do use the single quotes, just happened to key doubles for the email. Actually, it's good idea for all variable assignments. Philip Thompson wrote: On Mar 26, 2008, at 6:28 PM, Al wrote: Depends on the server and it's load. I've strung together some rather large html strings and they aways take far less time than the transient time on the internet. I used to use OB extensively until one day I took the time to measure the difference. I don't recall the numbers; but, I do recall it was not worth the slight extra trouble to use OB. Now, I simple assemble by html strings with $report .= foo; And then echo $report at the end. It also makes the code very easy to read and follow. You might as well take it a step further. Change the above to: $report .= 'foo'; This way for literal strings, the PHP parser doesn't have to evaluate this string to determine if anything needs to be translated (e.g., $report .= I like to $foo). A minimal speedup, but nonetheless... ~Philip Andrew Ballard wrote: On Wed, Mar 26, 2008 at 1:18 PM, Al [EMAIL PROTECTED] wrote: You are really asking an HTML question, if you think about it. At the PHP level, either use output buffering or assemble all your html string as a variable and then echo it. The goal is to compress the string into the minimum number of packets. Yes, but do so smartly. Excessive string concatenation can slow things down as well. On most pages you probably won't notice much difference, but I have seen instances where the difference was painfully obvious. Andrew Yes and if your script takes .0002 seconds to run using double quotes it will only take .00019 seconds with single (depending upon how many quotes you have of course) :-) I'm coming in late to this thread so sorry if I missed this :) How much of a difference would it make if you have something like this: echo $foo bar bar bar bar $foo $foo; verses: echo $foo . bar bar bar bar . $foo $foo; ?In other words... You have a large application which is most likely to be faster? :) -Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424-9337 www.raoset.com [EMAIL PROTECTED] I would assume your 2 examples to be the same because the point is that the PHP interpreter must parse for vars to substitute when it encounters double-quotes whether there are any vars in it or not. With single-quotes the interpreter does not have to worry about it. Regardless, the speed diff is probably negligible, hence my flame inviting post. :-) ehh my answer is meant to be here: nope. it parses both, since you may have escaped characters within single quotes too. so the difference only comes in when you actually have a variable in the string. sorry its morning ;) greets, Zoltán Németh -Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
Eric Butera wrote: On Thu, Mar 27, 2008 at 12:41 PM, Peter Ford [EMAIL PROTECTED] wrote: Jason Pruim wrote: On Mar 27, 2008, at 11:05 AM, Shawn McKenzie wrote: Al wrote: Good point. I usually do use the single quotes, just happened to key doubles for the email. Actually, it's good idea for all variable assignments. Philip Thompson wrote: On Mar 26, 2008, at 6:28 PM, Al wrote: Depends on the server and it's load. I've strung together some rather large html strings and they aways take far less time than the transient time on the internet. I used to use OB extensively until one day I took the time to measure the difference. I don't recall the numbers; but, I do recall it was not worth the slight extra trouble to use OB. Now, I simple assemble by html strings with $report .= foo; And then echo $report at the end. It also makes the code very easy to read and follow. You might as well take it a step further. Change the above to: $report .= 'foo'; This way for literal strings, the PHP parser doesn't have to evaluate this string to determine if anything needs to be translated (e.g., $report .= I like to $foo). A minimal speedup, but nonetheless... ~Philip Andrew Ballard wrote: On Wed, Mar 26, 2008 at 1:18 PM, Al [EMAIL PROTECTED] wrote: You are really asking an HTML question, if you think about it. At the PHP level, either use output buffering or assemble all your html string as a variable and then echo it. The goal is to compress the string into the minimum number of packets. Yes, but do so smartly. Excessive string concatenation can slow things down as well. On most pages you probably won't notice much difference, but I have seen instances where the difference was painfully obvious. Andrew Yes and if your script takes .0002 seconds to run using double quotes it will only take .00019 seconds with single (depending upon how many quotes you have of course) :-) I'm coming in late to this thread so sorry if I missed this :) How much of a difference would it make if you have something like this: echo $foo bar bar bar bar $foo $foo; verses: echo $foo . bar bar bar bar . $foo $foo; ?In other words... You have a large application which is most likely to be faster? :) There was a discussion about this a few weeks ago - ISTR that the compiler does wierd things with double-quoted strings, something like tokenising the words and checking each bit for lurking variables. So in fact echo $foo bar bar bar bar $foo $foo; is slowest (because there *are* variables to interpolate, echo $foo . bar bar bar bar .$foo. .$foo; is a bit faster, but the double-quoted bits cause some slow-down, echo $foo . ' bar bar bar bar '.$foo.' '.$foo; is a bit faster again - the single quoted bits pass through without further inspection, and finally echo $foo,' bar bar bar bar ',$foo,' ',$foo; is actually the fastest, because the strings are not concatenated before output. I think that was the overall summary - I can't locate the original post to verify (or attribute) but it's in this list somewhere... Cheers -- Peter Ford phone: 01580 89 Developer fax: 01580 893399 Justcroft International Ltd., Staplehurst, Kent -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Can you prove these statements with real benchmarks that are current? Ilia said that it is a myth that there is a performance difference between and ' in one of his talks. I found one recent post on the subject in gmane: http://article.gmane.org/gmane.comp.php.general/169028 The poster's results are as I remembered, except that was building a string, not echoing: possibly not quite the same. So I tried it myself, adapting to using echo (to the ob to avaoid printing forty million * foo bar bar ...). For an extra wheeze, I also tried ?=$foo? syntax embedded in HTML to see if that is as bad as people make out. I didn't try HEREDOC syntax, because it is difficult to reproduce exactly the same output - newlines get added to the output. To get thing to run I needed to increase time out, and reduce the string to avoid filling the PHP memory limit I have set at the moment. Here is the code: ?php ini_set('max_execution_time',300); $foo = 'f'; ob_start(); $time[1] = microtime(TRUE); for($x = 0; $x 1000; $x++){ echo $foo b b b b $foo $foo; } $time[2] = microtime(TRUE); ob_end_clean(); ob_start(); $time[3] = microtime(TRUE); for($x = 0; $x 1000; $x++){ echo $foo . ' b b b b '.$foo.' '.$foo; } $time[4] = microtime(TRUE); ob_end_clean(); ob_start(); $time[5] = microtime(TRUE); for($x = 0; $x 1000; $x++){ echo $foo . b b b b .$foo. .$foo; } $time[6] = microtime(TRUE); ob_end_clean(); ob_start(); $time[7] =
Re: [PHP] Re: optimilize web page loading
On Fri, 2008-03-28 at 09:14 +0100, Zoltán Németh wrote: 2008. 03. 27, csütörtök keltezéssel 09.29-kor Philip Thompson ezt írta: On Mar 26, 2008, at 6:28 PM, Al wrote: Depends on the server and it's load. I've strung together some rather large html strings and they aways take far less time than the transient time on the internet. I used to use OB extensively until one day I took the time to measure the difference. I don't recall the numbers; but, I do recall it was not worth the slight extra trouble to use OB. Now, I simple assemble by html strings with $report .= foo; And then echo $report at the end. It also makes the code very easy to read and follow. You might as well take it a step further. Change the above to: $report .= 'foo'; This way for literal strings, the PHP parser doesn't have to evaluate this string to determine if anything needs to be translated (e.g., $report .= I like to $foo). A minimal speedup, but nonetheless... that above statement is simply not true. parsing foo and 'foo' is all the same a good read about it: http://blog.libssh2.org/index.php?/archives/28-How-long-is-a-piece-of-string.html Nope, parsing is not the same, the resultant bytecode is the same, but parsing is not. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
On Fri, 2008-03-28 at 09:31 +0100, Zoltán Németh wrote: 2008. 03. 28, péntek keltezéssel 09.19-kor Zoltán Németh ezt írta: 2008. 03. 27, csütörtök keltezéssel 10.21-kor Shawn McKenzie ezt írta: Jason Pruim wrote: On Mar 27, 2008, at 11:05 AM, Shawn McKenzie wrote: Al wrote: Good point. I usually do use the single quotes, just happened to key doubles for the email. Actually, it's good idea for all variable assignments. Philip Thompson wrote: On Mar 26, 2008, at 6:28 PM, Al wrote: Depends on the server and it's load. I've strung together some rather large html strings and they aways take far less time than the transient time on the internet. I used to use OB extensively until one day I took the time to measure the difference. I don't recall the numbers; but, I do recall it was not worth the slight extra trouble to use OB. Now, I simple assemble by html strings with $report .= foo; And then echo $report at the end. It also makes the code very easy to read and follow. You might as well take it a step further. Change the above to: $report .= 'foo'; This way for literal strings, the PHP parser doesn't have to evaluate this string to determine if anything needs to be translated (e.g., $report .= I like to $foo). A minimal speedup, but nonetheless... ~Philip Andrew Ballard wrote: On Wed, Mar 26, 2008 at 1:18 PM, Al [EMAIL PROTECTED] wrote: You are really asking an HTML question, if you think about it. At the PHP level, either use output buffering or assemble all your html string as a variable and then echo it. The goal is to compress the string into the minimum number of packets. Yes, but do so smartly. Excessive string concatenation can slow things down as well. On most pages you probably won't notice much difference, but I have seen instances where the difference was painfully obvious. Andrew Yes and if your script takes .0002 seconds to run using double quotes it will only take .00019 seconds with single (depending upon how many quotes you have of course) :-) I'm coming in late to this thread so sorry if I missed this :) How much of a difference would it make if you have something like this: echo $foo bar bar bar bar $foo $foo; verses: echo $foo . bar bar bar bar . $foo $foo; ?In other words... You have a large application which is most likely to be faster? :) I would assume your 2 examples to be the same because the point is that the PHP interpreter must parse for vars to substitute when it encounters double-quotes whether there are any vars in it or not. With single-quotes the interpreter does not have to worry about it. Regardless, the speed diff is probably negligible, hence my flame inviting post. :-) ehh my answer is meant to be here: It's still wrong :) nope. it parses both, since you may have escaped characters within single quotes too. so the difference only comes in when you actually have a variable in the string. sorry its morning ;) Aaah, that's why you're confused :P ;) Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
2008. 03. 28, péntek keltezéssel 09.00-kor Robert Cummings ezt írta: On Fri, 2008-03-28 at 09:31 +0100, Zoltán Németh wrote: 2008. 03. 28, péntek keltezéssel 09.19-kor Zoltán Németh ezt írta: 2008. 03. 27, csütörtök keltezéssel 10.21-kor Shawn McKenzie ezt írta: Jason Pruim wrote: On Mar 27, 2008, at 11:05 AM, Shawn McKenzie wrote: Al wrote: Good point. I usually do use the single quotes, just happened to key doubles for the email. Actually, it's good idea for all variable assignments. Philip Thompson wrote: On Mar 26, 2008, at 6:28 PM, Al wrote: Depends on the server and it's load. I've strung together some rather large html strings and they aways take far less time than the transient time on the internet. I used to use OB extensively until one day I took the time to measure the difference. I don't recall the numbers; but, I do recall it was not worth the slight extra trouble to use OB. Now, I simple assemble by html strings with $report .= foo; And then echo $report at the end. It also makes the code very easy to read and follow. You might as well take it a step further. Change the above to: $report .= 'foo'; This way for literal strings, the PHP parser doesn't have to evaluate this string to determine if anything needs to be translated (e.g., $report .= I like to $foo). A minimal speedup, but nonetheless... ~Philip Andrew Ballard wrote: On Wed, Mar 26, 2008 at 1:18 PM, Al [EMAIL PROTECTED] wrote: You are really asking an HTML question, if you think about it. At the PHP level, either use output buffering or assemble all your html string as a variable and then echo it. The goal is to compress the string into the minimum number of packets. Yes, but do so smartly. Excessive string concatenation can slow things down as well. On most pages you probably won't notice much difference, but I have seen instances where the difference was painfully obvious. Andrew Yes and if your script takes .0002 seconds to run using double quotes it will only take .00019 seconds with single (depending upon how many quotes you have of course) :-) I'm coming in late to this thread so sorry if I missed this :) How much of a difference would it make if you have something like this: echo $foo bar bar bar bar $foo $foo; verses: echo $foo . bar bar bar bar . $foo $foo; ?In other words... You have a large application which is most likely to be faster? :) I would assume your 2 examples to be the same because the point is that the PHP interpreter must parse for vars to substitute when it encounters double-quotes whether there are any vars in it or not. With single-quotes the interpreter does not have to worry about it. Regardless, the speed diff is probably negligible, hence my flame inviting post. :-) ehh my answer is meant to be here: It's still wrong :) nope. it parses both, since you may have escaped characters within single quotes too. so the difference only comes in when you actually have a variable in the string. sorry its morning ;) Aaah, that's why you're confused :P yeah maybe. you're right, the bytecode is the same. but somewhere I heard that the parsing is the same too - because escaped characters can be in any string, though I'm not that sure about this anymore, as my link proved something else ;) greets Zoltán Németh ;) Cheers, Rob. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
On Fri, 2008-03-28 at 14:46 +0100, Zoltán Németh wrote: yeah maybe. you're right, the bytecode is the same. but somewhere I heard that the parsing is the same too - because escaped characters can be in any string, though I'm not that sure about this anymore, as my link proved something else ;) Single quoted strings do support some escape characters. As far as I know only you can only escape a single quote and a backslash when creating a string via single quotes. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
2008. 03. 28, péntek keltezéssel 10.24-kor Robert Cummings ezt írta: On Fri, 2008-03-28 at 14:46 +0100, Zoltán Németh wrote: yeah maybe. you're right, the bytecode is the same. but somewhere I heard that the parsing is the same too - because escaped characters can be in any string, though I'm not that sure about this anymore, as my link proved something else ;) Single quoted strings do support some escape characters. As far as I know only you can only escape a single quote and a backslash when creating a string via single quotes. yes, but I think the parser would still need to tokenize the string and verify each token whether it contains an escape character or not - which should be the same process as tokenizing and checking for escape character and $ signs. greets, Zoltán Németh Cheers, Rob. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
On Fri, 2008-03-28 at 15:30 +0100, Zoltán Németh wrote: 2008. 03. 28, péntek keltezéssel 10.24-kor Robert Cummings ezt írta: On Fri, 2008-03-28 at 14:46 +0100, Zoltán Németh wrote: yeah maybe. you're right, the bytecode is the same. but somewhere I heard that the parsing is the same too - because escaped characters can be in any string, though I'm not that sure about this anymore, as my link proved something else ;) Single quoted strings do support some escape characters. As far as I know only you can only escape a single quote and a backslash when creating a string via single quotes. yes, but I think the parser would still need to tokenize the string and verify each token whether it contains an escape character or not - which should be the same process as tokenizing and checking for escape character and $ signs. Nope, when processing a single quoted string there should be 4 available parse branches: EOF '(end of string) \ EOF \ ' anything else anything else Whereas with a double quoted string you have something along the lines of: EOF (end of string) $(begin variable) {(possible begin interpolation) $(begin interpolation) \ EOF \ ' t n r x v f digit anything else anything else So presuming no variable is embeded and assuming no escaped characters... double quotes still need to check for the beginning of variable interpolation which has 2 different start possibilities. With respect to creating the byte code single quotes have 4 branches, double quotes have 6 branches in the simplest of cases with no escape and no interpolation. So one would expect compile time for double quotes to be approximately 33% slower than for single quotes. Once compiled though, the point is moot especially since most sites use a bytecode cache like eAccelerator or APC. Even without a cache htough, the time difference is tncy, and this is just for informational purposes :) There are usually bigger eggs to fry when optimizing. One last thing though... even if this were escaped and even if there were fifty variables embedded, a good bytecode optimizer (not quite the same as a bytecode cacher) would optimize the bytecode for caching so that the string is broken up according to what needs to be interpolated and what does not. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
At 9:14 AM +0100 3/28/08, Zoltán Németh wrote: This way for literal strings, the PHP parser doesn't have to evaluate this string to determine if anything needs to be translated (e.g., $report .= I like to $foo). A minimal speedup, but nonetheless... that above statement is simply not true. parsing foo and 'foo' is all the same a good read about it: http://blog.libssh2.org/index.php?/archives/28-How-long-is-a-piece-of-string.html greets, Zoltán Németh I read it, but it still doesn't disprove the premise. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
At 10:59 AM -0400 3/28/08, Robert Cummings wrote: Nope, when processing a single quoted string there should be 4 available parse branches: EOF '(end of string) \ EOF \ ' anything else anything else Whereas with a double quoted string you have something along the lines of: EOF (end of string) $(begin variable) {(possible begin interpolation) $(begin interpolation) \ EOF \ ' t n r x v f digit anything else anything else So presuming no variable is embeded and assuming no escaped characters... double quotes still need to check for the beginning of variable interpolation which has 2 different start possibilities. With respect to creating the byte code single quotes have 4 branches, double quotes have 6 branches in the simplest of cases with no escape and no interpolation. So one would expect compile time for double quotes to be approximately 33% slower than for single quotes. Once compiled though, the point is moot especially since most sites use a bytecode cache like eAccelerator or APC. Even without a cache htough, the time difference is tncy, and this is just for informational purposes :) There are usually bigger eggs to fry when optimizing. One last thing though... even if this were escaped and even if there were fifty variables embedded, a good bytecode optimizer (not quite the same as a bytecode cacher) would optimize the bytecode for caching so that the string is broken up according to what needs to be interpolated and what does not. As always, thanks for your most excellent explanation. I figured that something along those lines was happening. I didn't consider the escape concerns. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
My method was. Store into global thingy. Then echo very end of the page. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
On Thu, Mar 27, 2008 at 7:28 AM, Al [EMAIL PROTECTED] wrote: Depends on the server and it's load. I've strung together some rather large html strings and they aways take far less time than the transient time on the internet. I used to use OB extensively until one day I took the time to measure the difference. I don't recall the numbers; but, I do recall it was not worth the slight extra trouble to use OB. Now, I simple assemble by html strings with $report .= foo; And then echo $report at the end. It also makes the code very easy to read and follow. Andrew Ballard wrote: On Wed, Mar 26, 2008 at 1:18 PM, Al [EMAIL PROTECTED] wrote: You are really asking an HTML question, if you think about it. At the PHP level, either use output buffering or assemble all your html string as a variable and then echo it. The goal is to compress the string into the minimum number of packets. Yes, but do so smartly. Excessive string concatenation can slow things down as well. On most pages you probably won't notice much difference, but I have seen instances where the difference was painfully obvious. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I am also doing the same way. assemble the string and echo it at the end
Re: [PHP] Re: optimilize web page loading
On Mar 26, 2008, at 6:28 PM, Al wrote: Depends on the server and it's load. I've strung together some rather large html strings and they aways take far less time than the transient time on the internet. I used to use OB extensively until one day I took the time to measure the difference. I don't recall the numbers; but, I do recall it was not worth the slight extra trouble to use OB. Now, I simple assemble by html strings with $report .= foo; And then echo $report at the end. It also makes the code very easy to read and follow. You might as well take it a step further. Change the above to: $report .= 'foo'; This way for literal strings, the PHP parser doesn't have to evaluate this string to determine if anything needs to be translated (e.g., $report .= I like to $foo). A minimal speedup, but nonetheless... ~Philip Andrew Ballard wrote: On Wed, Mar 26, 2008 at 1:18 PM, Al [EMAIL PROTECTED] wrote: You are really asking an HTML question, if you think about it. At the PHP level, either use output buffering or assemble all your html string as a variable and then echo it. The goal is to compress the string into the minimum number of packets. Yes, but do so smartly. Excessive string concatenation can slow things down as well. On most pages you probably won't notice much difference, but I have seen instances where the difference was painfully obvious. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
Good point. I usually do use the single quotes, just happened to key doubles for the email. Actually, it's good idea for all variable assignments. Philip Thompson wrote: On Mar 26, 2008, at 6:28 PM, Al wrote: Depends on the server and it's load. I've strung together some rather large html strings and they aways take far less time than the transient time on the internet. I used to use OB extensively until one day I took the time to measure the difference. I don't recall the numbers; but, I do recall it was not worth the slight extra trouble to use OB. Now, I simple assemble by html strings with $report .= foo; And then echo $report at the end. It also makes the code very easy to read and follow. You might as well take it a step further. Change the above to: $report .= 'foo'; This way for literal strings, the PHP parser doesn't have to evaluate this string to determine if anything needs to be translated (e.g., $report .= I like to $foo). A minimal speedup, but nonetheless... ~Philip Andrew Ballard wrote: On Wed, Mar 26, 2008 at 1:18 PM, Al [EMAIL PROTECTED] wrote: You are really asking an HTML question, if you think about it. At the PHP level, either use output buffering or assemble all your html string as a variable and then echo it. The goal is to compress the string into the minimum number of packets. Yes, but do so smartly. Excessive string concatenation can slow things down as well. On most pages you probably won't notice much difference, but I have seen instances where the difference was painfully obvious. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
Al wrote: Good point. I usually do use the single quotes, just happened to key doubles for the email. Actually, it's good idea for all variable assignments. Philip Thompson wrote: On Mar 26, 2008, at 6:28 PM, Al wrote: Depends on the server and it's load. I've strung together some rather large html strings and they aways take far less time than the transient time on the internet. I used to use OB extensively until one day I took the time to measure the difference. I don't recall the numbers; but, I do recall it was not worth the slight extra trouble to use OB. Now, I simple assemble by html strings with $report .= foo; And then echo $report at the end. It also makes the code very easy to read and follow. You might as well take it a step further. Change the above to: $report .= 'foo'; This way for literal strings, the PHP parser doesn't have to evaluate this string to determine if anything needs to be translated (e.g., $report .= I like to $foo). A minimal speedup, but nonetheless... ~Philip Andrew Ballard wrote: On Wed, Mar 26, 2008 at 1:18 PM, Al [EMAIL PROTECTED] wrote: You are really asking an HTML question, if you think about it. At the PHP level, either use output buffering or assemble all your html string as a variable and then echo it. The goal is to compress the string into the minimum number of packets. Yes, but do so smartly. Excessive string concatenation can slow things down as well. On most pages you probably won't notice much difference, but I have seen instances where the difference was painfully obvious. Andrew Yes and if your script takes .0002 seconds to run using double quotes it will only take .00019 seconds with single (depending upon how many quotes you have of course) :-) -Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
On Mar 27, 2008, at 11:05 AM, Shawn McKenzie wrote: Al wrote: Good point. I usually do use the single quotes, just happened to key doubles for the email. Actually, it's good idea for all variable assignments. Philip Thompson wrote: On Mar 26, 2008, at 6:28 PM, Al wrote: Depends on the server and it's load. I've strung together some rather large html strings and they aways take far less time than the transient time on the internet. I used to use OB extensively until one day I took the time to measure the difference. I don't recall the numbers; but, I do recall it was not worth the slight extra trouble to use OB. Now, I simple assemble by html strings with $report .= foo; And then echo $report at the end. It also makes the code very easy to read and follow. You might as well take it a step further. Change the above to: $report .= 'foo'; This way for literal strings, the PHP parser doesn't have to evaluate this string to determine if anything needs to be translated (e.g., $report .= I like to $foo). A minimal speedup, but nonetheless... ~Philip Andrew Ballard wrote: On Wed, Mar 26, 2008 at 1:18 PM, Al [EMAIL PROTECTED] wrote: You are really asking an HTML question, if you think about it. At the PHP level, either use output buffering or assemble all your html string as a variable and then echo it. The goal is to compress the string into the minimum number of packets. Yes, but do so smartly. Excessive string concatenation can slow things down as well. On most pages you probably won't notice much difference, but I have seen instances where the difference was painfully obvious. Andrew Yes and if your script takes .0002 seconds to run using double quotes it will only take .00019 seconds with single (depending upon how many quotes you have of course) :-) I'm coming in late to this thread so sorry if I missed this :) How much of a difference would it make if you have something like this: echo $foo bar bar bar bar $foo $foo; verses: echo $foo . bar bar bar bar . $foo $foo; ?In other words... You have a large application which is most likely to be faster? :) -Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424-9337 www.raoset.com [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
Jason Pruim wrote: On Mar 27, 2008, at 11:05 AM, Shawn McKenzie wrote: Al wrote: Good point. I usually do use the single quotes, just happened to key doubles for the email. Actually, it's good idea for all variable assignments. Philip Thompson wrote: On Mar 26, 2008, at 6:28 PM, Al wrote: Depends on the server and it's load. I've strung together some rather large html strings and they aways take far less time than the transient time on the internet. I used to use OB extensively until one day I took the time to measure the difference. I don't recall the numbers; but, I do recall it was not worth the slight extra trouble to use OB. Now, I simple assemble by html strings with $report .= foo; And then echo $report at the end. It also makes the code very easy to read and follow. You might as well take it a step further. Change the above to: $report .= 'foo'; This way for literal strings, the PHP parser doesn't have to evaluate this string to determine if anything needs to be translated (e.g., $report .= I like to $foo). A minimal speedup, but nonetheless... ~Philip Andrew Ballard wrote: On Wed, Mar 26, 2008 at 1:18 PM, Al [EMAIL PROTECTED] wrote: You are really asking an HTML question, if you think about it. At the PHP level, either use output buffering or assemble all your html string as a variable and then echo it. The goal is to compress the string into the minimum number of packets. Yes, but do so smartly. Excessive string concatenation can slow things down as well. On most pages you probably won't notice much difference, but I have seen instances where the difference was painfully obvious. Andrew Yes and if your script takes .0002 seconds to run using double quotes it will only take .00019 seconds with single (depending upon how many quotes you have of course) :-) I'm coming in late to this thread so sorry if I missed this :) How much of a difference would it make if you have something like this: echo $foo bar bar bar bar $foo $foo; verses: echo $foo . bar bar bar bar . $foo $foo; ?In other words... You have a large application which is most likely to be faster? :) -Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424-9337 www.raoset.com [EMAIL PROTECTED] I would assume your 2 examples to be the same because the point is that the PHP interpreter must parse for vars to substitute when it encounters double-quotes whether there are any vars in it or not. With single-quotes the interpreter does not have to worry about it. Regardless, the speed diff is probably negligible, hence my flame inviting post. :-) -Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
Shawn McKenzie wrote: Jason Pruim wrote: On Mar 27, 2008, at 11:05 AM, Shawn McKenzie wrote: Al wrote: Good point. I usually do use the single quotes, just happened to key doubles for the email. Actually, it's good idea for all variable assignments. Philip Thompson wrote: On Mar 26, 2008, at 6:28 PM, Al wrote: Depends on the server and it's load. I've strung together some rather large html strings and they aways take far less time than the transient time on the internet. I used to use OB extensively until one day I took the time to measure the difference. I don't recall the numbers; but, I do recall it was not worth the slight extra trouble to use OB. Now, I simple assemble by html strings with $report .= foo; And then echo $report at the end. It also makes the code very easy to read and follow. You might as well take it a step further. Change the above to: $report .= 'foo'; This way for literal strings, the PHP parser doesn't have to evaluate this string to determine if anything needs to be translated (e.g., $report .= I like to $foo). A minimal speedup, but nonetheless... ~Philip Andrew Ballard wrote: On Wed, Mar 26, 2008 at 1:18 PM, Al [EMAIL PROTECTED] wrote: You are really asking an HTML question, if you think about it. At the PHP level, either use output buffering or assemble all your html string as a variable and then echo it. The goal is to compress the string into the minimum number of packets. Yes, but do so smartly. Excessive string concatenation can slow things down as well. On most pages you probably won't notice much difference, but I have seen instances where the difference was painfully obvious. Andrew Yes and if your script takes .0002 seconds to run using double quotes it will only take .00019 seconds with single (depending upon how many quotes you have of course) :-) I'm coming in late to this thread so sorry if I missed this :) How much of a difference would it make if you have something like this: echo $foo bar bar bar bar $foo $foo; verses: echo $foo . bar bar bar bar . $foo $foo; ?In other words... You have a large application which is most likely to be faster? :) -Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424-9337 www.raoset.com [EMAIL PROTECTED] I would assume your 2 examples to be the same because the point is that the PHP interpreter must parse for vars to substitute when it encounters double-quotes whether there are any vars in it or not. With single-quotes the interpreter does not have to worry about it. Regardless, the speed diff is probably negligible, hence my flame inviting post. :-) -Shawn Actually: echo $foo . bar bar bar bar . $foo $foo; Should be: echo $foo . bar bar bar bar . $foo . . $foo; So this would be 'slower' because there are 2 separate instances of double-quotes for the interpreter to parse for vars. -Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
At 10:21 AM -0500 3/27/08, Shawn McKenzie wrote: I would assume your 2 examples to be the same because the point is that the PHP interpreter must parse for vars to substitute when it encounters double-quotes whether there are any vars in it or not. With single-quotes the interpreter does not have to worry about it. Regardless, the speed diff is probably negligible, hence my flame inviting post. :-) -Shawn -Shawn: The time difference is not the reason why I use single and double quotes. I do it for two reasons: 1) It's good coding practice to know what's happening in the background and consider it; 2) If I use a single quote, then I know that statement does not contain a variable -- it's a form of documentation for me. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
Jason Pruim wrote: On Mar 27, 2008, at 11:05 AM, Shawn McKenzie wrote: Al wrote: Good point. I usually do use the single quotes, just happened to key doubles for the email. Actually, it's good idea for all variable assignments. Philip Thompson wrote: On Mar 26, 2008, at 6:28 PM, Al wrote: Depends on the server and it's load. I've strung together some rather large html strings and they aways take far less time than the transient time on the internet. I used to use OB extensively until one day I took the time to measure the difference. I don't recall the numbers; but, I do recall it was not worth the slight extra trouble to use OB. Now, I simple assemble by html strings with $report .= foo; And then echo $report at the end. It also makes the code very easy to read and follow. You might as well take it a step further. Change the above to: $report .= 'foo'; This way for literal strings, the PHP parser doesn't have to evaluate this string to determine if anything needs to be translated (e.g., $report .= I like to $foo). A minimal speedup, but nonetheless... ~Philip Andrew Ballard wrote: On Wed, Mar 26, 2008 at 1:18 PM, Al [EMAIL PROTECTED] wrote: You are really asking an HTML question, if you think about it. At the PHP level, either use output buffering or assemble all your html string as a variable and then echo it. The goal is to compress the string into the minimum number of packets. Yes, but do so smartly. Excessive string concatenation can slow things down as well. On most pages you probably won't notice much difference, but I have seen instances where the difference was painfully obvious. Andrew Yes and if your script takes .0002 seconds to run using double quotes it will only take .00019 seconds with single (depending upon how many quotes you have of course) :-) I'm coming in late to this thread so sorry if I missed this :) How much of a difference would it make if you have something like this: echo $foo bar bar bar bar $foo $foo; verses: echo $foo . bar bar bar bar . $foo $foo; ?In other words... You have a large application which is most likely to be faster? :) There was a discussion about this a few weeks ago - ISTR that the compiler does wierd things with double-quoted strings, something like tokenising the words and checking each bit for lurking variables. So in fact echo $foo bar bar bar bar $foo $foo; is slowest (because there *are* variables to interpolate, echo $foo . bar bar bar bar .$foo. .$foo; is a bit faster, but the double-quoted bits cause some slow-down, echo $foo . ' bar bar bar bar '.$foo.' '.$foo; is a bit faster again - the single quoted bits pass through without further inspection, and finally echo $foo,' bar bar bar bar ',$foo,' ',$foo; is actually the fastest, because the strings are not concatenated before output. I think that was the overall summary - I can't locate the original post to verify (or attribute) but it's in this list somewhere... Cheers -- Peter Ford phone: 01580 89 Developer fax: 01580 893399 Justcroft International Ltd., Staplehurst, Kent -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
On Thu, Mar 27, 2008 at 12:41 PM, Peter Ford [EMAIL PROTECTED] wrote: Jason Pruim wrote: On Mar 27, 2008, at 11:05 AM, Shawn McKenzie wrote: Al wrote: Good point. I usually do use the single quotes, just happened to key doubles for the email. Actually, it's good idea for all variable assignments. Philip Thompson wrote: On Mar 26, 2008, at 6:28 PM, Al wrote: Depends on the server and it's load. I've strung together some rather large html strings and they aways take far less time than the transient time on the internet. I used to use OB extensively until one day I took the time to measure the difference. I don't recall the numbers; but, I do recall it was not worth the slight extra trouble to use OB. Now, I simple assemble by html strings with $report .= foo; And then echo $report at the end. It also makes the code very easy to read and follow. You might as well take it a step further. Change the above to: $report .= 'foo'; This way for literal strings, the PHP parser doesn't have to evaluate this string to determine if anything needs to be translated (e.g., $report .= I like to $foo). A minimal speedup, but nonetheless... ~Philip Andrew Ballard wrote: On Wed, Mar 26, 2008 at 1:18 PM, Al [EMAIL PROTECTED] wrote: You are really asking an HTML question, if you think about it. At the PHP level, either use output buffering or assemble all your html string as a variable and then echo it. The goal is to compress the string into the minimum number of packets. Yes, but do so smartly. Excessive string concatenation can slow things down as well. On most pages you probably won't notice much difference, but I have seen instances where the difference was painfully obvious. Andrew Yes and if your script takes .0002 seconds to run using double quotes it will only take .00019 seconds with single (depending upon how many quotes you have of course) :-) I'm coming in late to this thread so sorry if I missed this :) How much of a difference would it make if you have something like this: echo $foo bar bar bar bar $foo $foo; verses: echo $foo . bar bar bar bar . $foo $foo; ?In other words... You have a large application which is most likely to be faster? :) There was a discussion about this a few weeks ago - ISTR that the compiler does wierd things with double-quoted strings, something like tokenising the words and checking each bit for lurking variables. So in fact echo $foo bar bar bar bar $foo $foo; is slowest (because there *are* variables to interpolate, echo $foo . bar bar bar bar .$foo. .$foo; is a bit faster, but the double-quoted bits cause some slow-down, echo $foo . ' bar bar bar bar '.$foo.' '.$foo; is a bit faster again - the single quoted bits pass through without further inspection, and finally echo $foo,' bar bar bar bar ',$foo,' ',$foo; is actually the fastest, because the strings are not concatenated before output. I think that was the overall summary - I can't locate the original post to verify (or attribute) but it's in this list somewhere... Cheers -- Peter Ford phone: 01580 89 Developer fax: 01580 893399 Justcroft International Ltd., Staplehurst, Kent -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Can you prove these statements with real benchmarks that are current? Ilia said that it is a myth that there is a performance difference between and ' in one of his talks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
On Wed, Mar 26, 2008 at 1:18 PM, Al [EMAIL PROTECTED] wrote: You are really asking an HTML question, if you think about it. At the PHP level, either use output buffering or assemble all your html string as a variable and then echo it. The goal is to compress the string into the minimum number of packets. Yes, but do so smartly. Excessive string concatenation can slow things down as well. On most pages you probably won't notice much difference, but I have seen instances where the difference was painfully obvious. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimilize web page loading
Depends on the server and it's load. I've strung together some rather large html strings and they aways take far less time than the transient time on the internet. I used to use OB extensively until one day I took the time to measure the difference. I don't recall the numbers; but, I do recall it was not worth the slight extra trouble to use OB. Now, I simple assemble by html strings with $report .= foo; And then echo $report at the end. It also makes the code very easy to read and follow. Andrew Ballard wrote: On Wed, Mar 26, 2008 at 1:18 PM, Al [EMAIL PROTECTED] wrote: You are really asking an HTML question, if you think about it. At the PHP level, either use output buffering or assemble all your html string as a variable and then echo it. The goal is to compress the string into the minimum number of packets. Yes, but do so smartly. Excessive string concatenation can slow things down as well. On most pages you probably won't notice much difference, but I have seen instances where the difference was painfully obvious. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php