2,000,000 a very large number, might I say tens of millions!?!
This project optimizes the algorithm based on the Sieve of Eratosthenes, an ancient Greek mathematician, to find prime numbers. The code is optimized using memoization techniques. There are two techiniques being used:
I being by defining a
memoizefunction on the prototype of the built-in
Function, see here for details, for caching prior results. Within the running application, I can almost instantaneously provide results for values previously entered.
I initialize an array of primes and an array for the sieve outside the main function call, and I have several helper functions for determining the starting point for the sieve algorithm. This means that while searching for 10,000 primes may take
xamount of time, searching for 20,000 afterwards may take an equal amount of time, perhaps even less. This enables someone to incrementally get the algorithm to return tens of millions of primes without crashing the browser. In my first attempt, just to have fun replicating the algorithm, my app topped at 2 Million, and took almost a minute.
This project is best viewed on modern browsers, though some of the code could be brougth more up-to-date, so to speak.