Hello,
Well, I made a very simple script that generates a loop. One for PHP5 and one for PERL5.
The loop generates 1,000,000 numbers and meassures the time it took to do so.
The script redirects the output via the shell redirection to a file and then it tells you the benchmark results and it prints it to a file named "comparison".
My results are depressing...
perl: 1s
php: 8s
One more thing. If you run the script a few times, php starts to take longer to generate this. If you monitor your file size, you will see that the first 4.7 mb of the file take like 2 secs.... the rest (until it reaches 6.6 mb) takes ages!
I have already tweaded the php.ini file so php is allowed to use 512 M per script and the time limit for scripts to run is 60 secs.... no change
I will post the script file here and in my webpage
Critics... i am waiting... as you will se, I am not much of a scripter!
Enviroment
Pentium IV 1.8 Ghz
1024 Mb RAM - PCI 133
40 GB Hd (UDMA, 5200 rpm, etc)
Fedora Core IV (PHP5, PERL5.6.7)
--- script starts here ---
#!/bin/sh
Generate php_loop.php
echo Generating php loop...
cat > php_loop.php << EOF
<?php
\$t1 = microtime(true);
\$x = 0;
for(\$x>0; \$x<1000000; \$x++)
{
print "\$x\n";
}
\$t2 = microtime(true);
\$time = \$t2 - \$t1;
print "Time for PHP: \$t2 - \$t1 = \$time seconds";
?>
EOF
Generate php-cgi_loop.php
cat > php-cgi_loop.php << EOF
<?php
\$t1 = microtime(true);
\$x = 0;
for(\$x>0; \$x<1000000; \$x++)
{
print "\$x\n";
}
\$t2 = microtime(true);
\$time = \$t2 - \$t1;
print "Time for PHP-CGI: \$t2 - \$t1 = \$time seconds";
?>
EOF
Generate perl_loop.php
echo Generating PERL loop...
cat > perl_loop.pl << EOF
use integer;
\$t1 = time;
\$x = 0;
for(\$x>0; \$x<1000000; \$x++)
{
print "\$x\n";
}
\$t2 = time;
\$time = \$t2 - \$t1;
print "Time for PERL: \$t2 - \$t1 = \$time";
EOF
Run php_loop.php
echo Running PHP binary on the loop...
php php_loop.php > php_results.txt
echo Running PHP-CGI binary on the loop...
php php-cgi_loop.php > php-cgi_results.txt
Run perl_loop.php
echo Running PERL binary on the loop...
perl perl_loop.pl > perl_results.txt
#print results
printf "\n\n"
less php_results.txt | grep Time
printf "\n"
less php-cgi_results.txt | grep Time
printf "\n"
less perl_results.txt | grep Time
printf "\n"
less php_results.txt | grep Time > comparison
less php-cgi_results.txt | grep Time >> comparison
less perl_results.txt | grep Time >> comparison
exit 0
--- script ends here ---