运行此程序显示以下结果:
object ParallelTest {
def main(args: Array[String]) {
val start = System.nanoTime()
val list = (1 to 10000).toList.par
println("with par: elapsed: " + (System.nanoTime() - start) / 1000000 + " milliseconds")
val start2 = System.nanoTime()
val list2 = (1 to 10000).toList
println("without par: elapsed: " + (System.nanoTime() - start2) / 1000000 + " milliseconds")
}
}
.
with par: elapsed: 238 milliseconds
without par: elapsed: 0 milliseconds
如果我理解这些结果,使用par
需要更长的时间,因为“并行化” aList
需要将内容复制到并行数据结构?