Performance

We compare Stream performance to the same operations (filter, map, flatMap) done by Scala major collections

For example:

import scalqa.Stream.Enable._

val list = (1 to 1000).toList

scalqa.Util.Benchmark(
  ("List          ", () => list    .filter(_ % 2 == 0).flatMap(_ => list).map(_ / 2L).sum),
  ("List as Stream", () => list.all.filter(_ % 2 == 0).flatMap(_ => list).map(_ / 2L).sum))

// Final Output

Num Name           Ops/Sec %   Memory %   Control Value Avg
--- -------------- ------- --- ------ --- -----------------
1   List           39      16  18.2m  100 125000000
2   List as Stream 230     100 30.9k  0   125000000

The testing is done with Util.Benchmark tool, which is not very precise, but is easy to use, and it gives a good picture of comparative performance. Anyone can copy/paste the code and run it from anywhere

In this section multiple tests are presented for:

To get more credibility, the same tests are performed with JMH, and results are here

There are usually two kind of tests: for regular and specialized data. Stream operations are specialized for primitives (Byte, Char, Short, Int, Long, Float, Double) and should be considerably faster in those cases

The benchmarks were run with Oracle jre-1.8.191 and scala-library-2.13.0-M5