title: Scala Generic Type slow
body: <p>I do need to create a method for comparison for either Int or String or Char. Using AnyVal was not make it possible as there were no method's for &lt;, &gt; comparison.</p>
  <p>However Typing it into Ordered shows a significant slowness. Are there better ways to achieve this? The plan is to do a generic binary sorting, and found Generic typing decreases the performance.</p>
  <pre><code>def sample1[T &lt;% Ordered[T]](x:T) = { x &lt; (x) }
  def sample2(x:Ordered[Int]) = { x &lt; 1 }
  def sample3(x:Int) = { x &lt; 1 }
  
  val start1 = System.nanoTime
  sample1(5)
  println(System.nanoTime - start1)
  val start2 = System.nanoTime
  sample2(5)
  println(System.nanoTime - start2)
  val start3 = System.nanoTime
  sample3(5)
  println(System.nanoTime - start3)
  val start4 = System.nanoTime
  sample3(5)
  println(System.nanoTime - start4)
  val start5 = System.nanoTime
  sample2(5)
  println(System.nanoTime - start5)
  val start6 = System.nanoTime
  sample1(5)
  println(System.nanoTime - start6)
  </code></pre>
  <p>The results shows:</p>
  <blockquote>
  <p>Sample1:696122</p>
  <p>Sample2:45123</p>
  <p>Sample3:13947</p>
  <p>Sample3:5332</p>
  <p>Sample2:194438</p>
  <p>Sample1:497992</p>
  </blockquote>
  <p>Am I doing the incorrect way of handling Generics? Or should I be doing the old Java method of using Comparator in this case, sample as in:</p>
  <pre><code>object C extends Comparator[Int] {
    override def compare(a:Int, b:Int):Int = {
      a - b
    }
  }
  def sample4[T](a:T, b:T, x:Comparator[T]) {x.compare(a,b)}
  </code></pre>