use of org.eclipse.collections.impl.list.mutable.FastList in project eclipse-collections by eclipse.
the class SerialParallelLazyPerformanceTest method forEach.
private void forEach(FastList<Integer> collection) {
MutableList<Runnable> runnables = FastList.newList();
runnables.add(() -> this.basicSerialForEachPerformance(collection, SERIAL_RUN_COUNT));
int cores = Runtime.getRuntime().availableProcessors();
ExecutorService service = Executors.newFixedThreadPool(cores);
runnables.add(() -> {
MutableMap<Integer, Boolean> map = new ConcurrentHashMap<>();
this.basicParallelLazyForEachPerformance(collection, "Lambda", item -> map.put(item, Boolean.TRUE), PARALLEL_RUN_COUNT, cores, service);
});
runnables.add(() -> {
MutableMap<Integer, Boolean> map = new ConcurrentHashMap<>();
this.basicParallelLazyForEachPerformance(collection, "Procedure", (Procedure<Integer>) each -> map.put(each, Boolean.TRUE), PARALLEL_RUN_COUNT, cores, service);
});
runnables.add(() -> {
MutableMap<Integer, Boolean> map = new ConcurrentHashMap<>();
this.basicJava8ParallelLazyForEachPerformance(collection, "Lambda", item -> map.put(item, Boolean.TRUE), PARALLEL_RUN_COUNT);
});
List<Integer> arrayList = new ArrayList<>(collection);
runnables.add(() -> {
MutableMap<Integer, Boolean> map = new ConcurrentHashMap<>();
this.basicJava8ParallelLazyForEachPerformance(arrayList, "Lambda", item -> map.put(item, Boolean.TRUE), PARALLEL_RUN_COUNT);
});
runnables.add(() -> {
MutableMap<Integer, Boolean> map = new ConcurrentHashMap<>();
this.basicJava8ParallelLazyForEachPerformance(arrayList, "Consumer", each -> map.put(each, Boolean.TRUE), PARALLEL_RUN_COUNT);
});
this.shuffleAndRun(runnables);
service.shutdown();
try {
service.awaitTermination(1, TimeUnit.MINUTES);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
use of org.eclipse.collections.impl.list.mutable.FastList in project eclipse-collections by eclipse.
the class ListsTest method assertPresizedMultiReaderListEquals.
private static void assertPresizedMultiReaderListEquals(int initialCapacity, MultiReaderFastList<String> list) {
try {
Field delegateField = MultiReaderFastList.class.getDeclaredField("delegate");
delegateField.setAccessible(true);
FastList<String> delegate = (FastList<String>) delegateField.get(list);
Field itemsField = FastList.class.getDeclaredField("items");
itemsField.setAccessible(true);
Object[] items = (Object[]) itemsField.get(delegate);
Assert.assertEquals(initialCapacity, items.length);
} catch (SecurityException | NoSuchFieldException | IllegalAccessException e) {
throw new AssertionError(e);
}
}
use of org.eclipse.collections.impl.list.mutable.FastList in project eclipse-collections by eclipse.
the class DropIterableTest method forEachWithIndex.
@Test
public void forEachWithIndex() {
Sum sum = new IntegerSum(0);
FastList<Integer> indices = FastList.newList(5);
ObjectIntProcedure<Integer> indexRecordingAndSumProcedure = (each, index) -> {
indices.add(index);
sum.add(each);
};
this.dropIterable.forEachWithIndex(indexRecordingAndSumProcedure);
Assert.assertEquals(FastList.newListWith(0, 1, 2), indices);
Assert.assertEquals(12, sum.getValue().intValue());
indices.clear();
sum.add(sum.getValue().intValue() * -1);
this.emptyListDropIterable.forEachWithIndex(indexRecordingAndSumProcedure);
Assert.assertEquals(0, indices.size());
indices.clear();
sum.add(sum.getValue().intValue() * -1);
this.zeroCountDropIterable.forEachWithIndex(indexRecordingAndSumProcedure);
Assert.assertEquals(FastList.newListWith(0, 1, 2, 3, 4), indices);
Assert.assertEquals(15, sum.getValue().intValue());
indices.clear();
sum.add(sum.getValue().intValue() * -1);
this.nearCountDropIterable.forEachWithIndex(indexRecordingAndSumProcedure);
Assert.assertEquals(FastList.newListWith(0), indices);
Assert.assertEquals(5, sum.getValue().intValue());
indices.clear();
sum.add(sum.getValue().intValue() * -1);
this.sameCountDropIterable.forEachWithIndex(indexRecordingAndSumProcedure);
Assert.assertEquals(0, indices.size());
indices.clear();
sum.add(sum.getValue().intValue() * -1);
this.higherCountDropIterable.forEachWithIndex(indexRecordingAndSumProcedure);
Assert.assertEquals(0, indices.size());
}
use of org.eclipse.collections.impl.list.mutable.FastList in project eclipse-collections by eclipse.
the class DropWhileIterableTest method forEachWithIndex.
@Test
public void forEachWithIndex() {
Sum sum = new IntegerSum(0);
FastList<Integer> indices = FastList.newList(5);
ObjectIntProcedure<Integer> indexRecordingAndSumProcedure = (each, index) -> {
indices.add(index);
sum.add(each);
};
this.dropWhileIterable.forEachWithIndex(indexRecordingAndSumProcedure);
Assert.assertEquals(FastList.newListWith(0, 1, 2), indices);
Assert.assertEquals(12, sum.getValue().intValue());
indices.clear();
sum.add(sum.getValue().intValue() * -1);
this.emptyListDropWhileIterable.forEachWithIndex(indexRecordingAndSumProcedure);
Assert.assertEquals(0, indices.size());
indices.clear();
sum.add(sum.getValue().intValue() * -1);
this.alwaysFalseDropWhileIterable.forEachWithIndex(indexRecordingAndSumProcedure);
Assert.assertEquals(FastList.newListWith(0, 1, 2, 3, 4), indices);
Assert.assertEquals(15, sum.getValue().intValue());
indices.clear();
sum.add(sum.getValue().intValue() * -1);
this.mostlyFalseDropWhileIterable.forEachWithIndex(indexRecordingAndSumProcedure);
Assert.assertEquals(FastList.newListWith(0), indices);
Assert.assertEquals(5, sum.getValue().intValue());
indices.clear();
sum.add(sum.getValue().intValue() * -1);
this.alwaysTrueDropWhileIterable.forEachWithIndex(indexRecordingAndSumProcedure);
Assert.assertEquals(0, indices.size());
}
Aggregations