scala ranges versus lists performance on large collections

前端 未结 4 1966
醉梦人生
醉梦人生 2021-01-01 04:06

I ran a set of performance benchmarks for 10,000,000 elements, and I\'ve discovered that the results vary greatly with each implementation.

Can anybody explain why c

4条回答
  •  情话喂你
    2021-01-01 04:55

    In the first example you create a linked list with 10 elements by computing the steps of the range.

    In the second example you create a linked list with 10 millions of elements and filter it down to a new linked list with 10 elements.

    In the third example you create an array-backed buffer with 10 millions of elements which you traverse and print, no new array-backed buffer is created.

    Conclusion:

    Every piece of code does something different, that's why the performance varies greatly.

提交回复
热议问题