I have a large list to go through (1,500,000 points), each item should do a very small check. In just 30 seconds.
CPU usage when using Sequential is around 10%, so a lot of resources are not used.
The first thought was to use Parallel, but because of the limited length of time for each Parallel element it lasts longer than the serial Foreach, this is due to โ Why was the parallel version slower than the serial version in this example? โ, Which explains that creating each task will be worth the time.
So, I had another thought, and this is to divide the list into 4 (or more) equal faces and create a stream to iterate over the elements in order to get it faster.
Before creating my own class, is this a good approach? Or any other thoughts on how to speed up the process? Or you know the best way to handle this.
the code
Code I created for another parallel approach: (used in my own static class)
public static void ForEach<T>(IEnumerable<T> list, Action<T> body, int listDevide) {
Note: the variable "rest" to execute the last elements is not currently used in this example.
The solution is below, more information: http://msdn.microsoft.com/en-us/library/dd997411.aspx
optimization c # parallel-processing
user2331234
source share