-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Vitaly Tomilov edited this page Oct 11, 2021
·
72 revisions
This library contains 3 generators to choose from, based on your use case. Also check the benchmark performance figures.
-
Default
primeGenenerator()- produces primes from 2 untilmaxPrime = 9_007_199_254_740_881, which is hypothetically reachable, after running for 10+ years, so it can be considered infinite. This is the most efficient method in terms of memory and CPU usage, and can produce the first million primes in under half-second. -
Fast
primeGenerator({boost: N})- produces up toNprimes. It boosts performance 10x times over the default method, by pre-allocating a memory buffer for the calculation. However, this brings memory penalty, and soNis capped at 100mln primes, which at peak will eat 130MB of RAM. -
Offset
primeGenerator({start: S})- produces all primes betweenS(inclusive) andmaxPrime. It has the same memory + CPU efficiency as the default method, and is the best at finding primes above a certain range.
Note that you cannot combine start and boost options, because the fast method can only produce primes from the beginning, while the offset method cannot buffer its calculation.