Re: [PHP4BETA] eval - isn´t as slow as rumors about it
| From: | Zeev Suraski | Date: | Sun, 14 May 2000 21:39:40 +0000 |
| Subject: | Re: [PHP4BETA] eval - isn´t as slow as rumors about it | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-15011@lists.php.net to get a copy of this message | ||
That's not the reason why eval() is slow. eval() is slow because it invokes the compiler and compiles code, which is relatively expensive. If you have eval() in a loop or in a function, it means that you're compiling code repeatedly, which is slow; If you could implement the same logic without using eval(), it would compile just once, and thus end up executing much faster.
This doesn't come to say that eval() is too slow to be useful; But if you can do without it - you're better off.
Zeev
At 21:43 14/05/2000 , Faisal Nasim wrote:
| Hi, | just a little comment: | A few posts ago I was worried about being unable to reference in | variable function calls (like $str="db->fooobj->woo"; $this->$str();). | But we found out that there´s only the eval() way to do it. | Eval isn´t as slow as public thinks. I tested now and I use it to fill | multi-dim (between 2-6 dimensions) arrays based on a condition and I´m | surprised, it´s fast. Perhaps a small note on eval()´s documentation, | what eval() actually does and when it´s expected to be slow would help | some users. I would provide my multi-dim-array-fill code snipplet as an | advanced use of eval(). The only difference in eval() and regular code is that, the eval() code is directly read from a string and the rest from file (if not already read into a string). I haven't checked but I think its necessary to create a new buffer (yy_create_buffer(), default) to ask the lexer to parse it from a new location (a _very_ slight overhead). Enjoy! Faisal -- PHP 4.0 Beta Mailing List <http://www.php.net/version4/> To unsubscribe, e-mail: php4beta-unsubscribe@lists.php.net For additional commands, e-mail: php4beta-help@lists.php.net To contact the list administrators, e-mail: php4beta-admin@lists.php.net-- Zeev Suraski <zeev@zend.com> http://www.zend.com/