The Little Guy Posted January 31, 2010 Share Posted January 31, 2010 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 More sharing options...
The Little Guy Posted January 31, 2010 Author Share Posted January 31, 2010 sorry, I posted to the wrong link above the correct link: http://beta.phpsnips.com/snippet.php?id=104 Link to comment https://forums.phpfreaks.com/topic/190418-prime-number-check/#findComment-1004467 Share on other sites More sharing options...
The Little Guy Posted January 31, 2010 Author Share Posted January 31, 2010 Anyone know of a more efficient way to do this? Link to comment https://forums.phpfreaks.com/topic/190418-prime-number-check/#findComment-1004777 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.