Parallel ForEach Vs Foreach Loop in C#

6
28



C# – Parallel.ForEach Slower than ForEach?
What is the performance differences between using Parallel.ForEach and foreach loop?

A ForEach loop works like a For loop. The source collection is partitioned and the work is scheduled on multiple threads based on the system environment. The more processors on the system, the faster the parallel method runs. For some source collections, a sequential loop may be faster, depending on the size of the source, and the kind of work being performed.

Nguồn:https://wijstaanvooronzegrondrechten.org/

6 COMMENTS

  1. Man, nice effort but before posting this video you should have at least give it a thought. In like 90% of the times, the ForEach is faster than the Parallel.ForEach. This was not a very good way of displaying the benefits of TPL ForEach. You could have used some other operation where the difference of the performance would be significant.

LEAVE A REPLY

Please enter your comment!
Please enter your name here