Skip to content

Instantly share code, notes, and snippets.

@Yasushi
Created April 15, 2011 09:10
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 Yasushi/921438 to your computer and use it in GitHub Desktop.
Save Yasushi/921438 to your computer and use it in GitHub Desktop.
class Loop2(var n0: Int = 0) {
def calc(n: Int): Int = {
val n1 = n0 + (1 - 2 * (n % 2))
n0 = n
n1
}
}
object Loop2 {
def main(args: Array[String]) {
val l = new Loop2
var n = 1
var i = 0
val t1 = System.currentTimeMillis
while(i < Integer.MAX_VALUE) {
n = l.calc(n)
i+=1
}
val t2 = System.currentTimeMillis
println(n + "\nScala\t" + (t2 - t1)/1000.0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment