Hi all, PHP is usually thought to be faster than perl, but sometimes PHP runs slower than perl in some cases.
Belows is the example program in both PHP and Perl languages. This solves "x^2 + y^2 + z^2 = 32" and shows an array of (x, y, z) candidates. This program runs 1000 times for timekeeping. -- PHP version -- #!/usr/local/php/bin/php <?php $num = 32; for ($t=0; $t<1000; $t++) { for ($i=0; $i<=$num; $i++) { for ($j=0; $j<=$i; $j++) { for ($k=0; $k<=$j; $k++) { if ($i*$i + $j*$j + $k*$k == $num) echo "$i, $j, $k\n"; } } } } ?> -- Perl Version -- #!/usr/bin/perl $num = 32; for ($t=0; $t<1000; $t++) { for ($i=0; $i<=$num; $i++) { for ($j=0; $j<=$i; $j++) { for ($k=0; $k<=$j; $k++) { print "$i, $j, $k\n" if ($i*$i + $j*$j + $k*$k == $num); } } } } __END__ ... and, they results in: >> wassy% time ./4-3.php > /dev/null >> 40.480u 0.020s 0:40.59 99.7% 0+0k 0+0io 670pf+0w >> wassy% time ./4-3.pl > /dev/null >> 9.690u 0.010s 0:09.69 100.1% 0+0k 0+0io 282pf+0w Hey, perl is much faster, isn't it? :-( Is there any better way (i mean, better performance) to improve this? ...or, we have to declare Perl the winner sometimes? ps. I made C version and FORTRAN version. C was the fastest, and next comes FORTRAN: they are hundreds times faster than these script languages :-P --- Norihisa Washitake [EMAIL PROTECTED] http://www.washitake.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php