Hello

Then again, your code still does not make sense to me ...
Fully understand :-)

Not want wasting your time with my specific situation... but there are situation where it make sense :-)


For example... in my situation, i have time intensive (mathematically) operations to do in pure php
and was searching a way to speed this operations up.

With PHP's eval() feature, creating php code at run time, this would be, in my situation, a possible way.



Very simplified, i have to deal with the following:

function calculate($ints)
{
  $result = 0;
  for ($i=0; $i<10000000; ++$i) {
$result += $ints[0] + $ints[1] + $ints[2] + $ints[3] + $ints[4] + $ints[5];
  }
  return $result;
}
$ints = array(1,2,3,4,5,6);
$result = calculate($ints);



A faster way would be:

$ints = array(1,2,3,4,5,6);
eval('$calculate = function () {
  $result = 0;
  for ($i=0; $i<10000000; ++$i) {
$result += '.$ints[0].' + '.$ints[1].' + '.$ints[2].' + '.$ints[3].' + '.$ints[4].' + '.$ints[5].';
  }
  return $result;
};');
$result = $calculate();



The function code it self is in reality more complex and variable in the function-body length, but the princip is the same. The code-architecture, in my specific situation, requires also that the operation encapsulated in a function. (And for security: It is ensured that $int is an 1-dim array filled only with integers)

$calculate() works very fine and, of course, much faster than the hardcoded calculate(). Each time $ints is changing i also have, of course, re-define/creater $calculate() via eval.

In such situations, for performance reasons, it would makes sense using eval() for re/creating ano-functions, doesn't it?

And as long as the function-body has a fixed length each time re/creating the ano-function via eval() it would also not let grow the memory endless.

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to