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.

While each table represents a unique test done on one machine, each table can be done on different machines. The internal relative position/result of the test within a table can, therefore, be used, but an overall comparison of the times can not.

Lowest number per table is marked with *. Note that not all tests have been performed with all algorithms. This have been dependent on what has been under investigation.


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.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 1.000.000 to 2.000.000 (interval: 1.000.000)

Function While While skip ahead For
CheckForPrime1 16.078 14.665
CheckForPrime2 23.9532 21.5605
CheckForPrime3 25.6407 21.091
CheckForPrime4 12894.9781 12738.8425
CheckForPrime5 11.5815
CheckForPrime6 9.7153
Clone this wiki locally