note 89886 added to function.defined
| From: | tris+php at tfconsulting dot com dot au | Date: | Fri, 27 Mar 2009 02:40:18 +0000 |
| Subject: | note 89886 added to function.defined | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-152509@lists.php.net to get a copy of this message | ||
Before using defined() have a look at the following benchmarks:
true 0.65ms
$true 0.69ms (1)
$config['true'] 0.87ms
TRUE_CONST 1.28ms (2)
true 0.65ms
defined('TRUE_CONST') 2.06ms (3)
defined('UNDEF_CONST') 12.34ms (4)
isset($config['def_key']) 0.91ms (5)
isset($config['undef_key']) 0.79ms
isset($empty_hash[$good_key]) 0.78ms
isset($small_hash[$good_key]) 0.86ms
isset($big_hash[$good_key]) 0.89ms
isset($small_hash[$bad_key]) 0.78ms
isset($big_hash[$bad_key]) 0.80ms
PHP Version 5.2.6, Apache 2.0, Windows XP
Each statement was executed 1000 times and while a 12ms overhead on 1000 calls isn't going to
have the end users tearing their hair out, it does throw up some interesting results when comparing
to if(true):
1) if($true) was virtually identical
2) if(TRUE_CONST) was almost twice as slow - I guess that the substitution isn't done at
compile time (I had to double check this one!)
3) defined() is 3 times slower if the constant exists
4) defined() is 19 TIMES SLOWER if the constant doesn't exist!
5) isset() is remarkably efficient regardless of what you throw at it (great news for anyone
implementing array driven event systems - me!)
May want to avoid if(defined('DEBUG'))...
----
Server IP: 117.104.160.194
Probable Submitter: 121.214.143.34
----
Manual Page -- http://www.php.net/manual/en/function.defined.php
Edit -- https://master.php.net/note/edit/89886
Del: integrated -- https://master.php.net/note/delete/89886/integrated
Del: useless -- https://master.php.net/note/delete/89886/useless
Del: bad code -- https://master.php.net/note/delete/89886/bad+code
Del: spam -- https://master.php.net/note/delete/89886/spam
Del: non-english -- https://master.php.net/note/delete/89886/non-english
Del: in docs -- https://master.php.net/note/delete/89886/in+docs
Del: other reasons-- https://master.php.net/note/delete/89886
Reject -- https://master.php.net/note/reject/89886
Search -- https://master.php.net/manage/user-notes.php