Repository navigation
Benchmarks
No thing, that is supposed to be fast, is complete without some benchmarks. I'm using JMH for this and I'm quite sure, I'm doing several thing severly wrong while using JMH. The suite can be found in the benchmark module.
[1..10000000](list of 10 million integers)
-
1: (map + 1) -
2: (map + 1) (map + 1) (map + 1) (take 3)
1 is more like a copy from a data structure.
Performance characteristics will be dominated by whatever
data structure is used.
2 is targeting lazy and early-terminating techniques.
A strict system would have to copy every list 3 times only to throw
almost all of them away.
A non-strict system would only take the first 3 elements and then stop
the iteration.
-
java-collections-> Stream APIList.stream().map(...).collect(Collectors.toList) -
scala-collections-> strict Scala collectionsList.map(...).toVector-
breakout->(List.map(...)(collection.breakOut)): Vector[_] -
vector->List.toVector.map(...) -
streams->List.toStream.map(...).toVector -
view->List.view.map(...).toVector
-
-
java-transducers-> cognitec-labs/transducers-javafrom
s.c.i.List.asJavaintoj.u.ArrayList -
scala-transducers-> by yours trulyfrom
s.c.i.Listintoj.u.ArrayList
impl | op | ops/sec | error
-----------------:|--------------|------------:|----------: java-collections | 1 | 4.032 | 0.582 java-collections | 2 | 21.429 | 0.165 scala-collections | 1 | 0.903 | 0.953 scala-collections | 1 (breakout) | 10.663 | 1.426 scala-collections | 2 | 0.211 | 0.020 scala-collections | 2 (vector) | 1.784 | 0.243 scala-collections | 2 (streams) | 1326883.414 | 28699.299 scala-collections | 2 (view) | 2573804.816 | 67907.135 java-transducers | 1 | 4.584 | 0.775 java-transducers | 2 | 4888480.985 | 29433.815 scala-transducers | 1 | 5.460 | 0.769 scala-transducers | 2 | 6510019.388 | 80923.674
Both transducer implementations are similar. transducers-scala are specialized for ints, which is likely responsible for the better performance. Also, the benchmarks for Java code are written in Scala, I should probably rewrite them in Java to get a better picture.
After I implemented, that Builders that can be used during reduction, I wanted to compare different ways of transforming a List
[1..10000](list of 10 thousand integers)
- (map * 2) (filter % 4 == 0) (map - 42) (take 50)
I benchmarked scala.List, fj.data.List from functionaljava,
the old transducer implementation (v0.2), and the new implementation (v0.3)
impl | ops/sec | error
-----------------:|-----------:|----------: scala-collections | 5115.946 | 759.593 functionaljava | 4091.125 | 128.808 old-transducers | 50739.559 | 1597.439 new-transducers | 327457.876 | 11594.539