The msdn documentation about order preservation in PLINQ states the following about ForAll()
.
Now as an extension method:
It will process on multiple cores then will order the results, so there's the overhead of ordering. Here's an answer on benchmarking simple for vs parallel.
public static IEnumerable OrderedParallel(this IEnumerable list, Func action)
{
var unorderedResult = new ConcurrentBag<(long, T1)>();
Parallel.ForEach(list, (o, state, i) =>
{
unorderedResult.Add((i, action.Invoke(o)));
});
var ordered = unorderedResult.OrderBy(o => o.Item1);
return ordered.Select(o => o.Item2);
}
use like:
var result = Events.OrderedParallel(eventItem => ...);
Hope this will save you some time.