Skip to content

Instantly share code, notes, and snippets.

@natemurthy
Last active August 29, 2015 14:20
Show Gist options
  • Save natemurthy/ab7835e9e8969ca6ebaf to your computer and use it in GitHub Desktop.
Save natemurthy/ab7835e9e8969ca6ebaf to your computer and use it in GitHub Desktop.
import scala.collection.JavaConversions._
object ScalaSample {
def main(args: Array[String]) {
val rand = new java.util.Random()
final val N = Integer.valueOf(args(0))
var list = new java.util.ArrayList[Double](N)
for (i <- 0 until N) {
list.add(rand.nextDouble)
}
val s = System.nanoTime
var sum: Double = 0.0
for (l <- list) {
sum += l
}
val e = System.nanoTime
val time = String.valueOf((e-s)/1e9)
println("sum:" + String.valueOf(sum))
println("runtime: " + time)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment