Skip to content

Instantly share code, notes, and snippets.

@ishaaq
Created November 16, 2010 03:34
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 ishaaq/701374 to your computer and use it in GitHub Desktop.
Save ishaaq/701374 to your computer and use it in GitHub Desktop.
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