title: Scala vs. Java Regex matching: Big performance difference: Why?
body: <p>Request someone to please explain this Scala/Java differential -</p>
  
  <p><strong>Using Scala Pattern Matching</strong></p>
  
  <pre><code>scala&gt; def scalaRegex(count: Int) = {
   | val t1 = System.currentTimeMillis
   | val r_r = "test".r
   | val str = "test"
   | for (i &lt;- 0 to count) {
   |   str match {
   |     case r_r =&gt;
   |   }
   | }
   | val t2 = System.currentTimeMillis
   | val diff = t2 - t1
   | println(t2); println(t1); println(diff)
   | }
   scalaRegex: (count: Int)Unit
  
   scala&gt; scalaRegex(1000000000)
   1425976261692
   1425976261102
   590
  </code></pre>
  
  <p><strong>Using Java's simple way to match regex's -</strong></p>
  
  <pre><code>scala&gt; def javaRegex(count:Int) = {
   | val t1 = System.currentTimeMillis
   | val r_r = "test".r.pattern
   | val str = "test"
   | for (i &lt;- 0 to count) {
   |  r_r.matcher(str).matches()
   | }
   | val t2 = System.currentTimeMillis
   | val diff = t2 - t1
   | println(t2); println(t1); println(diff)
   | }
   javaRegex: (count: Int)Unit
  
   scala&gt; javaRegex(1000000000)
   1425976399868
   1425976335679
   64189
  </code></pre>
  
  <p>Thats a 100 times differential - <strong>whats happening?</strong></p>