-
Notifications
You must be signed in to change notification settings - Fork 1
Performance test for isPrimeSearch
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 has been dependent on what has been under investigation.
Results have shown that an ordinary while loop is almost never faster than wsa or for. The results where it was the fastest have been rerun, and the CheckPrime6 was the slowest with the while loop. Original results kept on the page but must be due to some fluke on the test machine.
*
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 | 13.6017 |
CheckForPrime2 | 23.9532 | 21.5605 | 20.5047 |
CheckForPrime3 | 25.6407 | 21.091 | 20.1112 |
CheckForPrime4 | 12894.9781 | 12738.8425 | 12184.6509 |
CheckForPrime5 | 11.5815 | 11.2439 | 10.7628 |
CheckForPrime6 | 9.7153 | 9.0733* | 9.0991 |
Searching from 0 to 100.000.000 (interval: 100.000.000)
Function | While | While skip ahead | For |
CheckForPrime6 | 1352.1654 | 1340.9117 | 1321.2643* |
Searching from 100.000 to 200.000 (interval: 100.000)
Function | While | While skip ahead | For |
CheckForPrime6 | 0.1438 | 0.1228* | 0.123 |