title: Scala pattern matching performance
body: <p>I encountered this problem while doing homework from coursera "scala specialization" (this is simplified version and doesn't contain any homework details, it's just array traversal)</p>
  
  <pre><code>val chars: Array[Char] = some array
  
  def fun1(idx:Int):Int = {
      some code here (including the stop condition)
  
      val c = chars(idx)
      c match{
        case '(' =&gt; fun1(idx+1)
        case  _  =&gt; fun1(idx+1)
      }
  
  }
  </code></pre>
  
  <p>This code is 4 times slower than </p>
  
  <pre><code>def fun2(idx: Int):Int = {
      some code here (including the stop condition)
  
      val c = chars(idx)
      (c == '(') match{
        case true =&gt; fun2(idx+1)
        case  _  =&gt; fun2(idx+1)
      }
  }
  </code></pre>
  
  <p>All I am doing is changing the pattern matching
  (I am running it using ScalMeter so I believe in the statistics).</p>
  
  <p>Can anyone explain this behavior? </p>