note 82239 deleted from function.eval by peehaa

From: Date: Mon, 09 Dec 2013 11:57:12 +0000
Subject: note 82239 deleted from function.eval by peehaa
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-197857@lists.php.net to get a copy of this message
Note Submitter: Luke at chaoticlogic dot net ---- 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.

« previous php.notes (#197857) next »