Created
December 21, 2011 13:20
-
-
Save tyrcho/1506019 to your computer and use it in GitHub Desktop.
fastest scala using arrays
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
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