UPDATE: I used Threading to split up the Loop in the Amount of Kernels (8 in my Case) and the complete Loop went through in under 1 second. So the problem is not, that the Operation is not faster with threading. Why did Parralel Extension fail in this case?
Hey everyone. I want to convert my ForEach with Parrallel.Foreach. The problem is, that the parralelisation brings hardly any advantage for me.
Original:
foreach (Entities.Buchung buchung in buchungen) { Int32 categoryID = manager.GetCategoryID(new Regelengine.Booking(buchung)); // Average 4ms buchung.Category = categoryID.ToString(); } Parallel:
System.Threading.Tasks.Parallel.ForEach(buchungen, buchung => { Int32 categoryID = manager.GetCategoryID(new Regelengine.Booking(buchung)); buchung.Category = categoryID.ToString(); }); Results:
--------------------------- Stopwatched Results for 1550 entries in the List: --------------------------- Parallel.Foreach 00:00:07.6599066 Average Foreach: 00:00:07.9791303 Maybe the problem is, that the actual action in the loop is so short? But nobody can tell me, that parallelising 1550 operations on an Intel I7 won't save any time.
Regelenginething.manager.GetCategoryID? What happens in the ctornew Regelengine.Booking?