Skip to content

Instantly share code, notes, and snippets.

@stepancheg
Created November 23, 2009 17:37
Show Gist options
  • Save stepancheg/241218 to your computer and use it in GitHub Desktop.
Save stepancheg/241218 to your computer and use it in GitHub Desktop.
Arrays.sort
def sort(a: Array[Int]) = {
java.util.Arrays.sort(a)
}
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 Array[Int](20 * 1000 * 1000)
val r = new java.util.Random
for (i <- 1 to a.length) {
a(i - 1) = r.nextInt()
}
profile("sort")(sort(a))
}
// vim: set ts=4 sw=4 et:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment