Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:42259 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81557 invoked from network); 14 Dec 2008 20:21:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Dec 2008 20:21:55 -0000 Authentication-Results: pb1.pair.com header.from=ilia@prohost.org; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=ilia@prohost.org; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain prohost.org from 74.125.46.30 cause and error) X-PHP-List-Original-Sender: ilia@prohost.org X-Host-Fingerprint: 74.125.46.30 yw-out-2324.google.com Received: from [74.125.46.30] ([74.125.46.30:60576] helo=yw-out-2324.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D3/F0-09557-1EA65494 for ; Sun, 14 Dec 2008 15:21:54 -0500 Received: by yw-out-2324.google.com with SMTP id 5so1048127ywb.83 for ; Sun, 14 Dec 2008 12:21:51 -0800 (PST) Received: by 10.65.44.11 with SMTP id w11mr5344352qbj.58.1229286110864; Sun, 14 Dec 2008 12:21:50 -0800 (PST) Received: from ?192.168.1.111? (CPE0018f8c0ee69-CM000f9f7d6664.cpe.net.cable.rogers.com [72.138.241.182]) by mx.google.com with ESMTPS id k30sm8689504qba.8.2008.12.14.12.21.48 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 14 Dec 2008 12:21:49 -0800 (PST) Cc: PHP internals Message-ID: <0E813FC7-E17D-4BB7-B719-24A5DCB8B9B6@prohost.org> To: David Grudl In-Reply-To: <49453D0F.6030405@grudl.com> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v929.2) Date: Sun, 14 Dec 2008 15:21:47 -0500 References: <49453D0F.6030405@grudl.com> X-Mailer: Apple Mail (2.929.2) Subject: Re: [PHP-DEV] Ternary operator optimization tip From: ilia@prohost.org (Ilia Alshanetsky) 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