consider the following:
object Foo {
def foo(x: Int) = {
var i = 0
var acc = 0L
val r = (3 until x)
while(i < x) {
acc += r.head
i += 1
}
acc
}
def callFoo() = {
val x = foo(100000)
println(x)
}
def main(args: Array[String]) {
val in = System.currentTimeMillis()
for(i <- 0 until 10000) {
callFoo()
}
println( (System.currentTimeMillis - in))
}
}
This runs in 4100ms on my machine. If you replace head with "start" it's 690ms
I'm making a pull request. One line change.