note 86820 added to function.eval
| From: | alexis at amigo dot com | Date: | Wed, 05 Nov 2008 04:20:11 +0000 |
| Subject: | note 86820 added to function.eval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-146151@lists.php.net to get a copy of this message | ||
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
----
Server IP: 190.2.55.3
Probable Submitter: 190.7.37.26
----
Manual Page -- http://www.php.net/manual/en/function.eval.php
Edit -- https://master.php.net/note/edit/86820
Del: integrated -- https://master.php.net/note/delete/86820/integrated
Del: useless -- https://master.php.net/note/delete/86820/useless
Del: bad code -- https://master.php.net/note/delete/86820/bad+code
Del: spam -- https://master.php.net/note/delete/86820/spam
Del: non-english -- https://master.php.net/note/delete/86820/non-english
Del: in docs -- https://master.php.net/note/delete/86820/in+docs
Del: other reasons-- https://master.php.net/note/delete/86820
Reject -- https://master.php.net/note/reject/86820
Search -- https://master.php.net/manage/user-notes.php