Created
November 23, 2009 17:15
-
-
Save stepancheg/241204 to your computer and use it in GitHub Desktop.
Collections.sort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class A(value: Int) | |
def sort(a: java.util.List[A]) = { | |
val c = new java.util.Comparator[A] { | |
override def compare(x: A, y: A) = x.value - y.value | |
} | |
java.util.Collections.sort(a, c) | |
} | |
def profile[T](what: String)(action: => T) = { | |
val start = System.currentTimeMillis() | |
val r = action | |
val delta = System.currentTimeMillis() - start | |
println(what + ": " + delta + "; " + r) | |
} | |
while (true) { | |
val a = new java.util.ArrayList[A] | |
val r = new java.util.Random | |
for (i <- 1 to 20 * 1000 * 1000) { | |
a.add(new A(r.nextInt())) | |
} | |
profile("sort")(sort(a)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment