Archive for December 2008
One of my friends (bwilliam) pointed out to me this webpage "Python vs PHP, Python runs slower?" It intrigued me since I already did something similar to this before here. It has been said that Python is faster than PHP, but why in this case, is Python clearly slower than PHP? I was hoping that the user comments on that page would have an answer, but most people just posted a better implementation of finding prime numbers. So I took a little bit of time out of my hectic schedule to find the cause.
Here are the two scripts written by Teifion in PHP and Python:
PHP:
$primeNumbers = array();
$output = ”;
for ($i = 2; $i < 100000; $i++)
{
$divisible = false;
foreach ($primeNumbers as $number)
{
if ($i % $number == 0)
{
$divisible = true;
}
}
if ($divisible == false)
{
$primeNumbers[] = $i;
$output .= $i;
}
}
echo $output;
?>
array · hectic schedule · implementation · little bit · prime numbers · primenumbers · python · scripts
