While it is slower due to the use of temp vars, in my experience
unless you have a few hundred operations involving ternary operator
you cannot even see the difference. Even then there are typically way
more important areas of code that need to be optimized. The only time
you can really tell its slower is in synthetic benchmarks.
On 14-Dec-08, at 12:06 PM, David Grudl wrote:
Hello,
ternary operator is very nice syntactic sugar...
$foo = $cond ? $bar : $baz;
...but it may slows down scripts. When $bar is array or relative big
string, it is better to aviod sugar and use if:
if ($cond) $foo = $bar; else $foo = $baz;
and reference counting will be used.
I don't know how difficult it is to implement, but it can be very
useful speed optimization for PHP 5.3 to improve ternary operator to
use reference counting.
David Grudl
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
Ilia Alshanetsky
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php