I’ve updated the Prime Time command line program to version 0.2. Changes includes a huge memory optimization and some minor performance optimizations. The computation time is reduced by about 12% so the test from the previous post (finding all primes up to the number 10 000 000) now takes only 4.602 seconds on average, compared to 5.211 seconds in version 0.1.
I also did a test on how long it took to find all primes up to 4 294 967 295 (the maximum value an unsigned 32-bit integer can hold) which took 5 hours, 17 minutes, 16 seconds and 70 milliseconds. The end result was a list of 203 280 221 primes. I ran the test without printing each individual prime to prevent disk IO operations from slowing down the process. Afterwards I ran the program with the – -print-primes option to write all the primes to a file. I ended up with a 2.2 GB large file and, when compressed with 7-Zip‘s most aggressive settings, it was reduced to about 200 MB. I choose the maximum unsigned 32-bit value because I knew that would go relatively fast on my 32-bit processor, but if you’re feeling adventurous you can crank it up to the maximum value of an unsigned 64-bit integer, which is the limit for the program. Just don’t complain to me when it never finishes. Both the binaries and source code is available for download.
NOTE: This post has been imported from my old it’s learning ePortfolio project blog.