std.parallelism curious results

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Oct 5 14:53:23 PDT 2014


On 10/05/2014 02:40 PM, Sativa wrote:

 >      foreach(i; thds) { ulong s = 0; for(ulong k = 0; k <
 > iter/numThreads; k++)

The for loop condition is executed at every iteration and division is an 
expensive operation. Apparently, the compiled does some optimization 
when the divisor is known at compile time.

Being 4, it is just a shift of 2 bits. Try something like 5, it is slow 
even for enum.

This solves the problem:

         const end = iter/numThreads;

         for(ulong k = 0; k < end; k++) {

Ali



More information about the Digitalmars-d-learn mailing list