----------------------------------- DtY Tue Jun 23, 2009 4:28 pm Comparison of Speeds in PHP ----------------------------------- I was wondering today just how much less efficient is double quotes than single quotes, and other such stuff. Here are the results: $ php -v PHP 5.2.9 (cli) (built: Apr 17 2009 03:29:12) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies Single Vs. Double Quotes Single Quotes Double Quotes Results should be able to run faster than double quoted strings. Interpolation Vs. Concatenation Interpolation Concatenation Results ++ Vs. +=1 ++ +=1 total [code] ++ +=1 user 0m0.015s 0m0.024s sys 0m0.014s 0m0.010s total 0m0.029s 0m0.034s[/code] This is good, the nicer one runs faster. (These are just on my computer, but the trends should be the same. As far as I know, they're accurate, unless PHP is doing optimizations on some of them, that it might not do in a place that's so obvious) ----------------------------------- rdrake Tue Jun 23, 2009 5:33 pm RE:Comparison of Speeds in PHP ----------------------------------- Try comparing i++ to ++i. PHP is full of all sorts of things like this. ----------------------------------- DtY Tue Jun 23, 2009 5:40 pm RE:Comparison of Speeds in PHP ----------------------------------- [code] $i++ ++$i real 0m0.194s 0m0.015s user 0m0.024s 0m0.014s total 0m0.218s 0m0.029s[/code] Oh wow :o I wonder how often anyone uses the return values from pre-/post-increments. Is there any use to having both of them? (Other than c does) ----------------------------------- DemonWasp Tue Jun 23, 2009 7:40 pm RE:Comparison of Speeds in PHP ----------------------------------- The ++i versus i++ thing is fairly frequent - even C++ has had issues with it. The biggest issue is when the increment is being done on an object with an overloaded ++ operator. Then, the ++i just does the increment. The i++ version makes a copy of the object, runs the increment on the copy it's going to keep, then uses the "backup" copy to complete the rest of the statement, even if there's nothing else to the statement. For what it's worth, I've almost never used the return value from a ++i or i++ . You can [url=http://compsci.ca/v3/viewtopic.php?t=20578]get into trouble with that in some languages (cough C / C++).