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
--- -------------- ------- --- ------ --- -----------------
1List391618.2m 1001250000002List as Stream 23010030.9k 0125000000
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
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
We compare Stream performance to the same operations (filter, map, flatMap) done by Scala major collections
For example:
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