Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70277 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 1875 invoked from network); 22 Nov 2013 05:38:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Nov 2013 05:38:52 -0000 Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.181 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.128.181 mail-ve0-f181.google.com Received: from [209.85.128.181] ([209.85.128.181:37268] helo=mail-ve0-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C5/31-28674-CEDEE825 for ; Fri, 22 Nov 2013 00:38:52 -0500 Received: by mail-ve0-f181.google.com with SMTP id oy12so553108veb.26 for ; Thu, 21 Nov 2013 21:38:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=9XX3Gl49VB/ZFmtbNTtGA2cc0thuQZpKs03QVQ7qtA8=; b=O8wdBgxpdxo5Bk0zPn2dn8NTOaE3/YE2GhdQD0rRJ1ZMB30+Z82xuvywYEJmoSpEYx wJWd6e/z504mRqhV9/kxFxZMkPgvFa3w1xf7U78fLsbayx3qVcJwqF2EZ72k39OfTNOX KZqP1OgN1zedhBe7yFwa0tUgxDrvO8TNBO7WzyCfcl0HaylrqUF58h7M45oPxPcq0ogk 7+xgmgcAQtNkhnIpAcNVmUoBdfPr9Y5uGGpqLlTXRBl4GlRbCu2CJrnh/zAdH/pw1kWt bgr7DplVgI6EG9RBt6Diuq2D6Z9llPBGbOE3yJB+yrhxd2J//XRvLi/2ZeO1McvdAtIP k0Ng== MIME-Version: 1.0 X-Received: by 10.221.64.17 with SMTP id xg17mr9558188vcb.5.1385098729882; Thu, 21 Nov 2013 21:38:49 -0800 (PST) Received: by 10.58.128.33 with HTTP; Thu, 21 Nov 2013 21:38:49 -0800 (PST) In-Reply-To: References: Date: Fri, 22 Nov 2013 13:38:49 +0800 Message-ID: To: Yasuo Ohgaki Cc: Bob Weinand , List PHP Mailing List Content-Type: multipart/alternative; boundary=001a1133158ec6095704ebbd6d06 Subject: Re: [PHP-DEV] [RFC] [VOTE] Constant scalar expressions From: tjerk.meesters@gmail.com (Tjerk Meesters) --001a1133158ec6095704ebbd6d06 Content-Type: text/plain; charset=ISO-8859-1 On Fri, Nov 22, 2013 at 1:11 PM, Yasuo Ohgaki wrote: > Hi Tjerk, > > On Fri, Nov 22, 2013 at 1:34 PM, Tjerk Meesters wrote: > >> Yes, of course that's all possible, because define() is just a function >> and therefore the normal assignment rules apply. However, you didn't >> mention the biggest drawback to such an approach, which is that it creates >> *global* constants; there's no way to namespace them. >> > > What was the reason why we don't have name space for define()? > Sorry for the confusion; of course it's possible to supply a fully qualified name to define(), thus making the constant appear in a namespace. With namespacing I also meant the ability to "attach" constants to class definitions, which isn't possible with define(). > >>> I prefer 'const' to be a static for better performance, since >>> we have dynamic constant by define() already. >>> >> >> Perhaps we'd have to consider how much performance is impacted on >> existing code, e.g. >> >> class A >> { >> const B = 123; >> } >> >> How much slower would that become if this RFC is accepted, cached or >> otherwise? >> > > I made a script to experiment. I have background job running on this > machine, > so I don't get stable result now, but embedding value is constantly faster. > > [yohgaki@dev tmp]$ php bench.php > Time: 6.4675929546356 > Time: 7.4527719020844 15.232544075653% slower > That's the time for a define()'ed constant. > Time: 7.4178550243378 14.69266968975% slower > That's the time for a const'ed constant. Still seems faster. > Time: 8.1120491027832 25.426092205894% slower > This is probably due to zend_fetch_class I assume? > Time: 7.4948840141296 15.883669035753% slower > I can't really explain that :) > [yohgaki@dev tmp]$ php bench.php > Time: 6.4104981422424 > Time: 7.7053151130676 20.198383060014% slower > Time: 8.022579908371 25.14752723358% slower > Time: 7.5032601356506 17.046444272519% slower > Time: 7.713919878006 20.332612331241% slower > This is way too much variation to be reliable. > > [yohgaki@dev tmp]$ cat bench.php > define('a', 1); > const b = 1; > > class foo { > const c = 1; > } > > class bar extends foo {}; > > $start = microtime(true); > for ($i=0 ; $i < 99999999; $i++) { > $v = 1 + 1; > } > $test0 = microtime(true) - $start; > echo 'Time: '. $test0 . PHP_EOL; > > $start = microtime(true); > for ($i=0 ; $i < 99999999; $i++) { > $v = 1 + a; > } > $test = microtime(true) - $start; > echo 'Time: '. $test . ' '. (($test - $test0)/$test0)*100 . '% slower' . > PHP_EOL; > > $start = microtime(true); > for ($i=0 ; $i < 99999999; $i++) { > $v = 1 + b; > } > $test = microtime(true) - $start; > echo 'Time: '. $test . ' '. (($test - $test0)/$test0)*100 . '% slower' . > PHP_EOL; > > $start = microtime(true); > for ($i=0 ; $i < 99999999; $i++) { > $v = 1 + foo::c; > } > $test = microtime(true) - $start; > echo 'Time: '. $test . ' '. (($test - $test0)/$test0)*100 . '% slower' . > PHP_EOL; > > $start = microtime(true); > for ($i=0 ; $i < 99999999; $i++) { > $v = 1 + bar::c; > } > $test = microtime(true) - $start; > echo 'Time: '. $test . ' '. (($test - $test0)/$test0)*100 . '% slower' . > PHP_EOL; > ?> > Actually, the test should be done against two separate builds: 1) build without patch 2) build with patch :) > -- > Yasuo Ohgaki > yohgaki@ohgaki.net > -- -- Tjerk --001a1133158ec6095704ebbd6d06--