Skip to content

Instantly share code, notes, and snippets.

@ryoppy
Last active October 12, 2017 04:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryoppy/6551813 to your computer and use it in GitHub Desktop.
Save ryoppy/6551813 to your computer and use it in GitHub Desktop.
正格と遅延(view)の計測
object Main extends App {
val a = (1 to 1000000)
// map2個
println("map2個-------------")
util.b { a.map(_+1).map(_+1) }.map(println)
util.b { a.map(_+1).map(_+1) }.map(println)
util.b { a.view.map(_+1).map(_+1).force }.map(println)
util.b { a.view.map(_+1).map(_+1).force }.map(println)
// map4個
println("map4個-------------")
util.b { a.map(_+1).map(_+1).map(_+1).map(_+1) }.map(println)
util.b { a.map(_+1).map(_+1).map(_+1).map(_+1) }.map(println)
util.b { a.view.map(_+1).map(_+1).map(_+1).map(_+1).force }.map(println)
util.b { a.view.map(_+1).map(_+1).map(_+1).map(_+1).force }.map(println)
// map6個
println("map6個-------------")
util.b { a.map(_+1).map(_+1).map(_+1).map(_+1).map(_+1).map(_+1) }.map(println)
util.b { a.map(_+1).map(_+1).map(_+1).map(_+1).map(_+1).map(_+1) }.map(println)
util.b { a.view.map(_+1).map(_+1).map(_+1).map(_+1).map(_+1).map(_+1).force }.map(println)
util.b { a.view.map(_+1).map(_+1).map(_+1).map(_+1).map(_+1).map(_+1).force }.map(println)
/*
map2個-------------
4074 ms
3591 ms
2185 ms (view)
2363 ms (view)
map4個-------------
7323 ms
7407 ms
2160 ms (view)
2728 ms (view)
map6個-------------
10738 ms
10155 ms
2739 ms (view)
2973 ms (view)
*/
}
object util {
def now = System.currentTimeMillis
def b(f: => Unit): Option[Long] = {
val start = now
for (i <- 1 to 10) f
Some(now - start)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment