Let's have a look at the output of a simple .NET Core console application, which benchmarks the techniques that we have just discussed. It shows one situation where parallelization doesn't help and actually makes things worse.
It then shows another situation where it does help.
When calculating a sum by accumulating 100,000 random integers between zero and ten, the quickest way is to use an array in a simple foreach loop. Using parallelization here makes the process much slower and, if used naively, without locking, will give an incorrect result, which is much worse.
When performing a more computationally intensive workload, ...