Skip to content

Instantly share code, notes, and snippets.

View AnkitKiet's full-sized avatar
🎯
Focusing

Ankit Maurya AnkitKiet

🎯
Focusing
View GitHub Profile
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() {
@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() {
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;
}
@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