title: Why is a parallel stream slower than a sequential stream?
body: <p>I have two functions solving the same problem.
  The first uses a sequential stream, and the second uses a parallel stream.</p>
  
  <pre><code>public static int digitalRoot(int n) {
      int sum = String.valueOf(n).chars().map(i -&gt; Integer.parseInt(String.valueOf((char) i))).sum();
      if (sum &gt;= 10) {
          return digitalRoot(sum);
      } else {
          return sum;
      }
  }
  
  public static int digitalRootParallel(int n) {
      int sum = String.valueOf(n).chars().parallel().
              map(i -&gt; Integer.parseInt(String.valueOf((char) i))).sum();
      if (sum &gt;= 10) {
          return digitalRootParallel(sum);
      } else {
          return sum;
      }
  }
  </code></pre>
  
  <p>I executed these functions once. 
  The parallel function <em>digitalRootParallel()</em> was faster (5 ms) than the sequential (32 ms) <em>digitalRoot()</em>.</p>
  
  <p>But when I executed each of them in a loop of 1.000.000, the sequential (117 ms) was faster than the parallel (1124 ms).</p>
  
  <pre><code>    for (int i = 0; i &lt; 1000000; i++) {
          sum = digitalRoot(n);
      }
  </code></pre>
  
  <p>Why is the loop with the parallel stream slower?</p>