Skip to content

Instantly share code, notes, and snippets.

@daimatz
Created January 28, 2014 06:44
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 daimatz/8663240 to your computer and use it in GitHub Desktop.
Save daimatz/8663240 to your computer and use it in GitHub Desktop.
Lambda を渡す。 g のほうがわずかに速いか
$ # 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
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