During the process of building encoders and loaders we at SourceGuardian run a simple test for all the new loaders to quickly check if there are any issues before entering the thorough testing phase especially for new versions. We run the same PHP code both in source and encoded for different versions of PHP and calculate the execution time just for fun. This produces interesting results in fact. The code itself does not matter, it's a rough Pi approximation and you may find it below. For that test we changed the number of iterations up to 10 000 000 to increase the overall execution time and minimize time calculation error. Actual time does not really matter as well as the machine that runs the code, but you can see the obvious difference between versions of PHP! Have fun trying it yourself if you wish!
The code:
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$t = microtime_float();
$pi = 4; $top = 4; $bot = 3; $minus = TRUE;
$accuracy = 10000000;
for($i = 0; $i < $accuracy; $i++)
{
$pi += ( $minus ? -($top/$bot) : ($top/$bot) );
$minus = ( $minus ? FALSE : TRUE);
$bot += 2;
}
print "Pi ~=: " . $pi . "\n";
$t2 = microtime_float();
print ($t2-$t)."\n";
(we know about the optional argument of microtime() but unfortunately old PHP 1.8.x etc does not!)
Results:
Happy coding!
Best Regards,
Alexander