title: How does sequential loop run faster than Parallel loop in C#?
body: <p>I tried a very minimal example:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Threading;
  using System.Collections.Concurrent;
  using System.Diagnostics;
  
  namespace TPLExample {
      class Program {
          static void Main(string[] args) {
              int[] dataItems = new int[100];
              double[] resultItems = new double[100];
  
              for (int i = 0; i &lt; dataItems.Length; ++i) {
                  dataItems[i] = i;
              }
  
              Stopwatch stopwatch = new Stopwatch();
  
              stopwatch.Reset();
              stopwatch.Start();
              Parallel.For(0, dataItems.Length, (index) =&gt; {
                  resultItems[index] = Math.Pow(dataItems[index], 2);
              });
              stopwatch.Stop();
              Console.WriteLine("TPL Time elapsed: {0}", stopwatch.Elapsed);
  
              stopwatch.Reset();
              stopwatch.Start();
              for (int i = 0; i &lt; dataItems.Length; ++i) {
                  resultItems[i] = Math.Pow(dataItems[i], 2);
              }
              stopwatch.Stop();
              Console.WriteLine("Sequential Time elapsed: {0}", stopwatch.Elapsed);
  
              WaitForEnterKey();
          }
  
          public static void WaitForEnterKey() {
              Console.WriteLine("Press enter to finish");
              Console.ReadLine();
          }
  
          public static void PrintMessage() {
              Console.WriteLine("Message printed");
          }
      }
  }
  </code></pre>
  
  <p>The output was:</p>
  
  <pre><code>TPL Time elapsed: 00:00:00.0010670
  Sequential Time elapsed: 00:00:00.0000178
  Press enter to finish
  </code></pre>
  
  <p>The sequential loop is way faster than TPL! How is this possible? From my understanding, calculation within the <code>Parallel.For</code> will be executed in parallel, so must it be faster?</p>