note 82239 added to function.eval

From: Date: Wed, 02 Apr 2008 08:26:46 +0000
Subject: note 82239 added to function.eval
Groups: php.notes 
Request: Send a blank email to php-notes+get-137849@lists.php.net to get a copy of this message
I thought it was pertinent to demonstrate just how slow the eval() function is when compared to pre-parsed code, so I wrote this. In my case, it took 54 seconds to execute the code 100,000,000 times through eval(), and only 4 seconds with pre-parsed code. <?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<10000000;$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,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 100,000,000 times.\n"; ?> I wish there was some way to parse code, store the pre-parsed binary in a variable, and then tell PHP to execute that variable as if it was part of the program. ---- Server IP: 208.69.120.35 Probable Submitter: 76.15.47.207 ---- Manual Page -- http://www.php.net/manual/en/function.eval.php Edit -- https://master.php.net/note/edit/82239 Del: integrated -- https://master.php.net/note/delete/82239/integrated Del: useless -- https://master.php.net/note/delete/82239/useless Del: bad code -- https://master.php.net/note/delete/82239/bad+code Del: spam -- https://master.php.net/note/delete/82239/spam Del: non-english -- https://master.php.net/note/delete/82239/non-english Del: in docs -- https://master.php.net/note/delete/82239/in+docs Del: other reasons-- https://master.php.net/note/delete/82239 Reject -- https://master.php.net/note/reject/82239 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#137849) next »