Created
January 28, 2014 06:44
-
-
Save daimatz/8663240 to your computer and use it in GitHub Desktop.
Lambda を渡す。 g のほうがわずかに速いか
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
$ # call f | |
$ for i in `seq 10`; scala Main | |
366 | |
379 | |
383 | |
372 | |
374 | |
373 | |
376 | |
367 | |
385 | |
386 | |
$ # call g | |
$ for i in `seq 10`; scala Main | |
361 | |
384 | |
353 | |
348 | |
349 | |
355 | |
363 | |
353 | |
354 | |
393 |
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
object Main { | |
def main(args: Array[String]) { | |
val to_s: Int => String = _.toString | |
val start = System.currentTimeMillis() | |
(0 until 5000000).foreach { i => | |
f(to_s, i) | |
// g(i) | |
} | |
val end = System.currentTimeMillis() | |
println(end - start) | |
} | |
def f(fun: Int => String, x: Int) = fun(x) | |
def g(x: Int) = x.toString | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment