note 114322 added to function.function-exists

From: Date: Fri, 07 Feb 2014 05:50:25 +0000
Subject: note 114322 added to function.function-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-198429@lists.php.net to get a copy of this message
function_exists() does not cache its query internally. by executing the following code $funcs = \array_shift(\get_defined_functions()); $l = new \core\utiles\loadTime; $times = 0; $l->start(); for($index = 0; $index<count($funcs); $index++) { foreach($funcs as $func) { $times++; if(\function_exists($func)) ; } } $s = $l->stop(); echo "<span style='color:green'>$times</span> took : $s"; # the output would be $> 2365444 took : 0.70324 By executing the $funcs = \array_shift(\get_defined_functions()); $l = new \core\utiles\loadTime; $times = 0; $l->start(); static $func_check = array(); for($index = 0; $index<count($funcs); $index++) { foreach($funcs as $func) { $times++; if(!isset($func_check[$func])) { if(\function_exists($func)) ; $func_check[$func] = 1; } else $func_check[$func]; } } $s = $l->stop(); echo "<span style='color:green'>$times</span> took : $s"; # the output would be $> 2365444 took : 0.53446 There is a 0.16878 seconds improvement, when you use static array to cache methods existence. ---- Server IP: 72.52.91.14 Probable Submitter: 72.52.91.14 ---- Manual Page -- http://php.net/manual/en/function.function-exists.php Edit -- https://master.php.net/note/edit/114322 Del: integrated -- https://master.php.net/note/delete/114322/integrated Del: useless -- https://master.php.net/note/delete/114322/useless Del: bad code -- https://master.php.net/note/delete/114322/bad+code Del: spam -- https://master.php.net/note/delete/114322/spam Del: non-english -- https://master.php.net/note/delete/114322/non-english Del: in docs -- https://master.php.net/note/delete/114322/in+docs Del: other reasons-- https://master.php.net/note/delete/114322 Reject -- https://master.php.net/note/reject/114322 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#198429) next »