Why aren't my scala futures more efficient?

后端 未结 2 2085
余生分开走
余生分开走 2021-02-12 23:35

I\'m running this scala code on a 32-bit quad-core Core2 system:

def job(i:Int,s:Int):Long = {
  val r=(i to 500000000 by s).map(_.toLong).foldLeft(0L)(_+_)
  pr         


        
2条回答
  •  执笔经年
    2021-02-13 00:38

    My guess is that the garbage collector is doing more work than the addition itself. So you're limited by what the garbage collector can manage. Try running the test again with something that doesn't create any objects (e.g. use a while loop instead of the range/map/fold). You can also play with the parallel GC options if your real application will hit the GC this heavily.

提交回复
热议问题