Last active
August 29, 2015 14:20
-
-
Save natemurthy/ab7835e9e8969ca6ebaf 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
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