note 86820 deleted from function.eval by peehaa

From: Date: Mon, 09 Dec 2013 11:56:32 +0000
Subject: note 86820 deleted from function.eval by peehaa
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-197853@lists.php.net to get a copy of this message
Note Submitter: alexis at amigo dot com ---- eval vs include i have to make a script to take code from a database and excute it, but i'm not sure is eval was hight server load than include, so i take the example of Luke at chaoticlogic dot net and test it, the results are great for eval: test.php <?php //establish a blank integer $increment=0; //establish the code to be executed //one hundred million times $code="\$increment++;"; //remember the time this test started $started=time(); //execute $code on hundred million times for ($i=0;$i<100000;$i++) { eval($code); } //find out how long it took, in //seconds $ended=time(); $spent=$ended-$started; //tell the user this print "Eval()ed code took $spent seconds to execute 100,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<100000;$i++) { include("increment.php"); } //find out how long it took, in //seconds $ended=time(); $spent=$ended-$started; //tell the user this print "Included file with Pre-parsed code took $spent seconds to execute 100,000 times.\n"; ?> increment.php <?php $increment++; ?> Eval()ed code took 0 seconds to execute 100,000 times. Included file with Pre-parsed code took 17 seconds to execute 100,000 times. i change 100,000,000 for 100,000 because the script take so much time

« previous php.notes (#197853) next »