-
-
Notifications
You must be signed in to change notification settings - Fork 639
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes memory leak of grouped iterator (#1907)
* Fixes memory leak of grouped iterator * Improved by throwing away unnecessary elements and by cleaning buffer before adding new elements. * Used Iterator instead of AbstractIterator * List.take/drop optimizations. See also #1910 * Added Iterator.sliding() benchmark * Based benchmark Iterators of element array * Fixed a bug/uncovered case * low-level optimization
- Loading branch information
1 parent
dc18105
commit c8b67e8
Showing
4 changed files
with
174 additions
and
38 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
javaslang-benchmark/src/test/java/javaslang/collection/IteratorBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* / \____ _ _ ____ ______ / \ ____ __ _______ | ||
* / / \/ \ / \/ \ / /\__\/ // \/ \ // /\__\ JΛVΛSLΛNG | ||
* _/ / /\ \ \/ / /\ \\__\\ \ // /\ \ /\\/ \ /__\ \ Copyright 2014-2017 Javaslang, http://javaslang.io | ||
* /___/\_/ \_/\____/\_/ \_/\__\/__/\__\_/ \_// \__/\_____/ Licensed under the Apache License, Version 2.0 | ||
*/ | ||
package javaslang.collection; | ||
|
||
import javaslang.JmhRunner; | ||
import org.junit.Test; | ||
import org.openjdk.jmh.annotations.*; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
|
||
import java.util.Random; | ||
|
||
import static javaslang.JmhRunner.Includes.*; | ||
import static javaslang.JmhRunner.getRandomValues; | ||
|
||
@SuppressWarnings({ "ALL", "unchecked", "rawtypes" }) | ||
public class IteratorBenchmark { | ||
|
||
static final Array<Class<?>> CLASSES = Array.of( | ||
Sliding.class | ||
); | ||
|
||
@Test | ||
public void testAsserts() { JmhRunner.runDebugWithAsserts(CLASSES); } | ||
|
||
public static void main(String... args) { | ||
JmhRunner.runDebugWithAsserts(CLASSES); | ||
JmhRunner.runNormalNoAsserts(CLASSES, JAVA, SCALA, JAVASLANG); | ||
} | ||
|
||
@State(Scope.Benchmark) | ||
public static class Base { | ||
@Param({ "10", "100", "1000" }) | ||
public int CONTAINER_SIZE; | ||
|
||
Integer[] ELEMENTS; | ||
|
||
scala.collection.Iterator<Integer> scalaIterator; | ||
javaslang.collection.Iterator<Integer> slangIterator; | ||
|
||
@Setup | ||
public void setup() { | ||
final Random random = new Random(0); | ||
ELEMENTS = getRandomValues(CONTAINER_SIZE, false, random); | ||
scalaIterator = (scala.collection.Iterator<Integer>) (Object) scala.collection.mutable.WrappedArray$.MODULE$.make(ELEMENTS).iterator(); | ||
slangIterator = Iterator.of(ELEMENTS); | ||
} | ||
} | ||
|
||
public static class Sliding extends Base { | ||
|
||
@Benchmark | ||
public void scala_persistent(Blackhole bh) { | ||
final scala.collection.Iterator.GroupedIterator values = scalaIterator.sliding(3, 1); | ||
while (values.hasNext()) { | ||
bh.consume(values.next()); | ||
} | ||
} | ||
|
||
@Benchmark | ||
public void slang_persistent(Blackhole bh) { | ||
final Iterator<Seq<Integer>> values = slangIterator.sliding(3); | ||
while (values.hasNext()) { | ||
bh.consume(values.next()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters