www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Parallelizing factorial computation

reply Uknown <sireeshkodali1 gmail.com> writes:
I was messing and tried comparing the performance of different 
ways to compute the factorial of a number. Here's the benchmark 
results:

recursive:	244 ms, 283 μs, and 2 hnsecs
loop:		241 ms, 412 μs, and 3 hnsecs
parallel:	1 sec, 784 ms, 829 μs, and 5 hnsecs


https://run.dlang.io/is/uyVlqu

I was quite surprised by the fact that parallel ran so much 
slower than recursive and loop implementations. Does anyone know 
why?
Aug 24 2018
parent reply Peter Alexander <peter.alexander.au gmail.com> writes:
On Friday, 24 August 2018 at 13:04:47 UTC, Uknown wrote:
 I was quite surprised by the fact that parallel ran so much 
 slower than recursive and loop implementations. Does anyone 
 know why?
n = 100 is too small to see parallelism gains. Try n = 10000 https://run.dlang.io/is/XDZTSd
Aug 24 2018
parent Uknown <sireeshkodali1 gmail.com> writes:
On Friday, 24 August 2018 at 20:43:46 UTC, Peter Alexander wrote:
 On Friday, 24 August 2018 at 13:04:47 UTC, Uknown wrote:
 I was quite surprised by the fact that parallel ran so much 
 slower than recursive and loop implementations. Does anyone 
 know why?
n = 100 is too small to see parallelism gains. Try n = 10000 https://run.dlang.io/is/XDZTSd
I was using n = 10000 originally, I reduced it because that wasn't running on run.dlang. Tried this again on my machine and you were right.
Aug 24 2018