Created
November 16, 2010 03:34
-
-
Save ishaaq/701374 to your computer and use it in GitHub Desktop.
This file contains 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 ArrayTest { | |
def time(thunkName: String, iter: Int, thunk: => Boolean) = { | |
// warm up... | |
for(i <- 1 to iter) thunk | |
// timed... | |
val start = System.currentTimeMillis() | |
for(i <- 1 to iter) thunk | |
val timing = System.currentTimeMillis() - start | |
println(String.format("Ran %d iterations of [%s] in %d ms.", iter.asInstanceOf[AnyRef], thunkName, timing.asInstanceOf[AnyRef])) | |
} | |
def main(args: Array[String]) = { | |
val array = Array("An", "array", "of", "test", "string") | |
def isArrayTest = array.getClass.isArray | |
def charAtTest = array.getClass.getName.charAt(0) == '[' | |
val iter = 100000000; | |
time("isArrayTest", iter, isArrayTest) | |
time("charAtTest", iter, charAtTest) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment