Jump to content

Prime number check


The Little Guy

Recommended Posts

I wrote a script that checks to see if a number is a prime number or not, it can be found here: http://beta.phpsnips.com/snippet.php?id=26

 

I was reading the comments, and people said that was a bad way to do this, but if I run the following script:

<?php
$num = 9000000;
$start = microtime(true);
if(is_prime($num))
echo $num.' is prime<br>';
else
echo $num.' is not prime<br>';
$end = microtime(true);

echo 'Script took '.($end - $start).' seconds to run.';
?>

 

the output displays:

9000000 is not prime

Script took 2.8687601089478 seconds to run.

 

Is 3 seconds too long for a script to check 9 million numbers?

 

I guess I need to speed it up, any suggestions?

Link to comment
https://forums.phpfreaks.com/topic/190418-prime-number-check/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.