Link Details

Link 368867 thumbnail
User 254199 avatar

By KlausG
via tellingmachine.com
Published: Feb 22 2010 / 22:56

n PHP is really no ideal way to test large integers and determine whether they are prime numbers or not. The most popular algorithm for finding prime numbers is a memory and resource hog. It is called The Sieve of Eratosthenes. Besides the Sieve I also implemented a prime number test by initializing an array of prime numbers from a file that contains the first 100,000 prime numbers. This is of course much faster, but would require files that contain all prime numbers up to a specific large number. The files of course could be partitioned, which would also increase performance.
  • 9
  • 0
  • 2753
  • 0

Comments

Add your comment
User 368023 avatar

yakkoh replied ago:

0 votes Vote down Vote up Reply

Faster for evenNumber is $number & 1
where & is the bit and.
see http://www.php.net/manual/en/language.operators.bitwise.php

also available for IsInteger: is_numeric and is_int.

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Voters For This Link (9)



Voters Against This Link (0)



    Java Performance Optimization
    Written by: Pierre-Hugues Charbonneau
    Featured Refcardz: Top Refcardz:
    1. Design Patterns
    2. OO JS
    3. Cont. Delivery
    4. Java EE7
    5. HTML5 Mobile
    1. Node.js
    2. Debugging JavaScript
    3. OO JS
    4. JSON
    5. Ajax