On 25/06/2021 11:35 pm, Andrew Rowley wrote:

I set the limit to 100,000,000 (the source validates results for multiples of 10) and got 10 passes in 5 seconds on my laptop. At 100,000,000 the bit map doesn't fit in processor cache which might be a significant penalty. 1,000,000 gives better granularity in the results.

For kicks I tried a limit of 1,000,000,000 which did 1 pass for 50,847,534 primes in 6.7 seconds.


I tried the larger numbers on z/OS as well. z/OS numbers are not really comparable system to system, because the single thread difference between slowest and fastest Z systems is something like 20x. However the relative numbers are interesting.

C++:

Primes to 1,000,000: 4829 passes
Primes to 100,000,000: 28 passes
Primes to 1,000,000,000: 2 passes in 5.1 seconds

The drop in performance with larger numbers was less than for the laptop, my guess is that is due to the larger CPU caches.

Java (zIIP offline so running on CP):

1,000,000: 4800 passes
100,000,000: 14 passes
1,000,000,000: 1 pass in 9 seconds

The drop in performance for Java was unexpected, my guess is that the boolean array is not optimized for 100,000,000 or 1,000,000,000 entries. If e.g. each entry is a byte instead of a bit the CPU cache impact would be much greater.

I decided to create a Java version using the same bit storage as the C++ version i.e. a byte array manipulating individual bits. Again results were interesting:

1,000,000: 2675 passes
100,000,000: 14 passes
1,000,000,000: 2 passes in 7 seconds

So it was slower for small numbers, but approached C++ speeds for the search to 1,000,000,000.

--
Andrew Rowley
Black Hill Software

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to