note 102528 deleted from function.eval by danbrown

From: Date: Sat, 19 Feb 2011 15:30:46 +0000
Subject: note 102528 deleted from function.eval by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-177137@lists.php.net to get a copy of this message
Note Submitter: aserg45 at NOSPAMPLZ yahoo NOSPAM dotcom ---- using the test given by Luke at chaoticlogic dot net, I modified it a little and added a test in which the ENTIRE loop was eval()'ed (not just the loop contents). <?php //establish a blank integer $increment=0; //establish the code to be executed $code="\$increment++;"; //remember the time this test started $started=time(); //execute $code one hundred million times for ($i=0;$i<10000000;$i++) eval($code); //find out how long it took, in //seconds $ended=time(); $spent=$ended-$started; //tell the user this print "Eval()ed LOOP CONTENTS took $spent seconds to execute 10,000,000 times.\n"; //re-establish a blank integer $increment=0; //establish the new code to be executed $code="for(\$i=0;\$i<10000000;\$i++)\$increment++;"; //remember the time this test started $started=time(); //execute $code eval($code); //find out how long it took, in //seconds $ended=time(); $spent=$ended-$started; //tell the user this print "Eval()ed COMPLETE LOOP took $spent seconds to execute 10,000,000 times.\n"; //re-establish that same blank integer $increment=0; //remember the time this second test //started $started=time(); //execute the test again, with //pre-parsed code for ($i=0;$i<10000000;$i++) $increment++; //find out how long it took, in //seconds $ended=time(); $spent=$ended-$started; //tell the user this print "Pre-parsed code took $spent seconds to execute 10,000,000 times.\n"; ?> On my system (PHP 5.2.9), this gives the following output: Eval()ed LOOP CONTENTS took 38 seconds to execute 10,000,000 times. Eval()ed COMPLETE LOOP took 2 seconds to execute 10,000,000 times. Pre-parsed code took 1 seconds to execute 10,000,000 times. So, the overhead of eval() appears to largely be in the initial call itself, the actual speed of bulk code inside eval() is many orders faster than repeated, smaller eval() calls.

« previous php.notes (#177137) next »