Why the following indexed parallel.foreach is almost twice slow compared with a normal sequential loop ? Is it related to resource contention?
static void Main(string[] args)
{
var values = Enumerable.Range(0, 100000).Select(v => v+v);
Stopwatch s = Stopwatch.StartNew();
//int index = 0;
//foreach (double value in values)
//{
// Console.WriteLine("{0}:\t{1}", index, value);
// index++;
//}
Parallel.ForEach(values, (value, pls, index) =>
{
Console.WriteLine("{0}:\t{1}", index, value);
index++;
});
Console.WriteLine(s.Elapsed.TotalMilliseconds);
Console.ReadLine();
}