Created
April 15, 2011 09:10
-
-
Save Yasushi/921438 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
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