Skip to content

Instantly share code, notes, and snippets.

@tyrcho
Created December 21, 2011 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyrcho/1506019 to your computer and use it in GitHub Desktop.
Save tyrcho/1506019 to your computer and use it in GitHub Desktop.
fastest scala using arrays
object BenchWithScala extends App {
val data = Array("foo", 23, true)
val n = 1000000
val result = new Array[Any](n * 3)
var i = 0
val before = System.currentTimeMillis()
while (i < n) {
var j = 0
while (j < 3) {
result(i * 3 + j) = foo(data(j))
j += 1
}
i += 1
}
printf("Took : %s ms, number of elements : %s %n", System.currentTimeMillis - before, result.size)
def foo(obj: Any) =
obj match {
case _: String => "String"
case _: Boolean => "Boolean"
case _: Integer => "Integer"
case _ => throw new IllegalArgumentException()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment