optimization - How Significant Is PHP Function Call Overhead? -


i'm relatively new php , learning idiosyncrasies specific language. 1 thing dinged lot (so i'm told) use many function calls , asked things work around them. here's 2 examples:

// change this: } catch (exception $e) {   print "it seems error " . $e->getcode() . " occured";   log("error: " . $e->getcode()); }  // this: } catch (exception $e) {   $code = $e->getcode();   print "it seems error " . $code . " occured";   log("error: " . $code); } 

2nd example

// change this: $customer->setproducts($products);  // this: if (!empty($products)) {   $customer->setproducts($products); } 

in first example find assigning $e->getcode() $code ads slight cognitive overhead; "what's '$code'? ah, it's code exception." whereas second example adds cyclomatic complexity. in both examples find optimization come @ cost of readability , maintainability.

is performance increase worth or micro optimization?

i should note we're stuck php 5.2 right now.

i've done rough bench tests , find function call performance hit on order of 10% 70% depending on nature of bench test. i'll concede significant. before catch block hit there call database , http end point. before $products set on $customer there complex sort happened $products array. at end of day optimization justify cost of making code harder read , maintain? or, although these examples simplifications, find 2nd examples easy or easier read first (am being wiener)?

can cite articles or studies this?

edit:

an example bench test:

<?php class foo {         private $list;         public function setlist($list) {                 $this->list = $list;         } }  $foo1 = new foo();  for($i = 0; $i < 1000000; $i++) {         $a = array();         if (!empty($a))                 $foo1->setlist($a); } ?> 

run file time command. on 1 particular machine takes average of 0.60 seconds after several runs. commenting out if (!empty($a)) causes take average of 3.00 seconds run.

clarification: these examples. 1st example demonstrates horrible exception handling , possible dry violation @ expense of simple, non-domain-specific example.

the canonical php implementation slow because it's easy implement , applications php aims @ not require raw performance fast function calls.

you might want consider other php implementations.

if writing applications should writing in php (dump data db browser on network) function call overhead not significant. don't go out of way duplicate code because afraid using function overhead.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -