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
private static final int LIST_SIZE = 20; | |
private int chunkSize; | |
private List<Integer> expectedChunk; | |
private int chunkIndex; | |
private int partitionedSize; | |
private static final List<Integer> list = IntStream.range(0, LIST_SIZE + random.nextInt(13)).boxed().collect(toList()); | |
@Setup(Level.Iteration) | |
public void setup() { |
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
@Benchmark | |
public void A3_smallListStreamPartitioned() { | |
final List<List<Integer>> result = list.stream() | |
.collect(partitioned(chunkSize)); | |
assertThat(result).hasSize(partitionedSize); | |
assertThat(result.get(chunkIndex)).isEqualTo(expectedChunk); | |
} | |
@Benchmark | |
public void A4_smallListToPartition() { |
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
public final class Partition<T> extends AbstractList<List<T>> { | |
private final List<T> list; | |
private final int chunkSize; | |
public Partition(List<T> list, int chunkSize) { | |
this.list = new ArrayList<>(list); | |
this.chunkSize = chunkSize; | |
} |
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
@Benchmark | |
public void C3_hugeListStreamPartitioned() { | |
final List<List<Integer>> result = list.stream() | |
.collect(partitioned(chunkSize)); | |
assertThat(result).hasSize(expectedSize); | |
assertThat(result.get(chunkIndex)).isEqualTo(expectedChunk); | |
} | |
@Benchmark |
OlderNewer