Skip to content

Performance test for isPrimeSearch

Dann Bleeker Pedersen edited this page Aug 31, 2019 · 18 revisions

whl – used a while loop to loop over all the numbers in the interval
wsa – used a while loop to loop over all the numbers in the interval, but added a skip-ahead if a prime is found, since no two primes bigger than 3 is next to each other
for – used a for loop to loop over all the numbers in the interval

Note that CheckForPrime6 is the best algorithm, however, there is not really a better solution for whl, wsa or for. More testing is needed.


**Searching from 200 to 400 (interval: 200)
|Function|While|While skip ahead|For|
|—-|—-|—-|—-|
|CheckForPrime1|0.0011|0.0006|0.0005|
|CheckForPrime2|0.0006|0.0004|0.0003|
|CheckForPrime3|0.0006|0.0003|0.0003|
|CheckForPrime4|0.001|0.0006|0.0005|
|CheckForPrime5|0.0002|0.0002|0.0001|
|CheckForPrime6|0.0002|0.0002|0.0001|

**Searching from 100.000 to 200.000 (interval: 100.000)
|Function|While|While skip ahead|For|
|—-|—-|—-|—-|
|CheckForPrime1|0.8063|0.7147|15.279|
|CheckForPrime2|12.418|11.394|24.082|
|CheckForPrime3|12.275|11.934|20.835|
|CheckForPrime4|2.385.757|2.484.423|3.407.217|
|CheckForPrime5|0.7796|10.944|10.462|
|CheckForPrime6|0.4709|10.758|0.7892|

**Searching from 200.000 to 400.000 (interval: 200.000)
|Function|While|While skip ahead|For|
|—-|—-|—-|—-|
|CheckForPrime1|13.967|0.991|0.9844|
|CheckForPrime2|24.884|14.276|15.029|
|CheckForPrime3|20.627|14.001|14.561|
|CheckForPrime4|4.267.062|3.728.232|3.509.704|
|CheckForPrime5|0.7277|0.6901|0.6733|
|CheckForPrime6|0.6428|0.5645|0.5591|

**Searching from 10.000.020.000 to 10.000.040.000 (interval: 20.000)
|Function|While|While skip ahead|For|
|—-|—-|—-|—-|
|CheckForPrime6|47.266|45.539|4.567|

**Searching from 10.000.000.000 to 10.000.100.000 (interval: 100.000)
|Function|While|While skip ahead|For|
|—-|—-|—-|—-|
|CheckForPrime6|231.544|229.244|226.361|

**Searching from 0 to 1.000.000 (interval: 1.000.000)
|Function|While|While skip ahead|For|
|—-|—-|—-|—-|
|CheckForPrime6|20.672|18.981|18.986|

Searching from 0 to 10.000.000 (interval: 10.000.000)
|Function|While|While skip ahead|For|
|—-|———|—-|
|CheckForPrime6|50.292510.552|529.251|

Clone this wiki locally