Created
July 11, 2013 03:23
-
-
Save zakki/5972291 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 A { | |
| val v = (x: Int) => x * 3 | |
| def f(x: Int) = x * 3 | |
| } | |
| object A { | |
| def v() { | |
| val a = new A | |
| var i = 0 | |
| var n = 1 | |
| while (i < 1000000) { | |
| n = a.v(n) | |
| i += 1 | |
| } | |
| println(n) | |
| } | |
| def f() { | |
| val a = new A | |
| var i = 0 | |
| var n = 1 | |
| while (i < 1000000) { | |
| n = a.f(n) | |
| i += 1 | |
| } | |
| println(n) | |
| } | |
| def main(args: Array[String]) { | |
| println("val/fun") | |
| (1 to 10) foreach { i => | |
| println(i) | |
| val t0 = System.nanoTime() | |
| v() | |
| val t1 = System.nanoTime() | |
| f() | |
| val t2 = System.nanoTime() | |
| v() | |
| val t3 = System.nanoTime() | |
| f() | |
| val t4 = System.nanoTime() | |
| println("val " + (t1 - t0) / 1000000.0 + "/ def" + (t2 - t1) / 1000000.0) | |
| println("val " + (t3 - t2) / 1000000.0 + "/ def" + (t4 - t3) / 1000000.0) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment