use of org.eclipse.collections.api.list.MutableList in project eclipse-collections by eclipse.
the class ParallelIterableTestCase method sumOfFloatConsistentRounding.
@Test
public void sumOfFloatConsistentRounding() {
FloatFunction<Integer> roundingSensitiveElementFunction = i -> (i <= 99995) ? 1.0e-18f : 1.0f;
MutableList<Integer> list = Interval.oneTo(100_000).toList().shuffleThis();
double baseline = this.getExpectedWith(list.toArray(new Integer[] {})).sumOfFloat(roundingSensitiveElementFunction);
for (Integer batchSize : BATCH_SIZES) {
this.batchSize = batchSize;
ParallelIterable<Integer> testCollection = this.newWith(list.toArray(new Integer[] {}));
Assert.assertEquals("Batch size: " + this.batchSize, baseline, testCollection.sumOfFloat(roundingSensitiveElementFunction), 1.0e-15d);
}
}
use of org.eclipse.collections.api.list.MutableList in project eclipse-collections by eclipse.
the class ParallelIterableTestCase method sumOfDoubleConsistentRounding.
@Test
public void sumOfDoubleConsistentRounding() {
DoubleFunction<Integer> roundingSensitiveElementFunction = i -> (i <= 99995) ? 1.0e-18d : 1.0d;
MutableList<Integer> list = Interval.oneTo(100_000).toList().shuffleThis();
double baseline = this.getExpectedWith(list.toArray(new Integer[] {})).sumOfDouble(roundingSensitiveElementFunction);
for (Integer batchSize : BATCH_SIZES) {
this.batchSize = batchSize;
ParallelIterable<Integer> testCollection = this.newWith(list.toArray(new Integer[] {}));
Assert.assertEquals("Batch size: " + this.batchSize, baseline, testCollection.sumOfDouble(roundingSensitiveElementFunction), 1.0e-15d);
}
}
use of org.eclipse.collections.api.list.MutableList 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.api.list.MutableList in project eclipse-collections by eclipse.
the class ParallelIterateTest method sumByBigInteger.
@Test
public void sumByBigInteger() {
MutableList<BigInteger> list = Interval.oneTo(100000).collect(Object::toString).collect(BigInteger::new).toList().shuffleThis();
MutableMap<String, BigInteger> sumByCount = ParallelIterate.sumByBigInteger(list, EVEN_OR_ODD_BI, bi -> BigInteger.valueOf(1L));
Assert.assertEquals(BigInteger.valueOf(50000L), sumByCount.get("Even"));
Assert.assertEquals(BigInteger.valueOf(50000L), sumByCount.get("Odd"));
MutableMap<String, BigInteger> sumByValue = ParallelIterate.sumByBigInteger(list, EVEN_OR_ODD_BI, bi -> bi);
Assert.assertEquals(Iterate.sumByBigInteger(list, EVEN_OR_ODD_BI, bi -> bi), sumByValue);
MutableMap<Integer, BigInteger> sumByValue2 = ParallelIterate.sumByBigInteger(list, bi -> bi.intValue() % 1000, bi -> bi);
Assert.assertEquals(Iterate.sumByBigInteger(list, bi -> bi.intValue() % 1000, bi -> bi), sumByValue2);
MutableList<BigInteger> list2 = Interval.oneTo(UNEVEN_COUNT_FOR_SUMBY).collect(Object::toString).collect(BigInteger::new).toList();
MutableMap<String, BigInteger> sumByValue3 = ParallelIterate.sumByBigInteger(list2, EVEN_OR_ODD_BI, bi -> bi);
Assert.assertEquals(Iterate.sumByBigInteger(list2, EVEN_OR_ODD_BI, bi -> bi), sumByValue3);
MutableMap<Integer, BigInteger> sumByValue4 = ParallelIterate.sumByBigInteger(list2, bi -> bi.intValue() % 1000, bi -> bi);
Assert.assertEquals(Iterate.sumByBigInteger(list2, bi -> bi.intValue() % 1000, bi -> bi), sumByValue4);
Interval small = Interval.oneTo(11);
MutableMap<String, BigInteger> smallSumByCount = ParallelIterate.sumByBigInteger(small, EVEN_OR_ODD, i -> BigInteger.valueOf(1L));
Assert.assertEquals(new BigInteger("5"), smallSumByCount.get("Even"));
Assert.assertEquals(new BigInteger("6"), smallSumByCount.get("Odd"));
}
use of org.eclipse.collections.api.list.MutableList in project eclipse-collections by eclipse.
the class FastListTest method testBAOSSize.
@Test
public void testBAOSSize() {
MutableList<MutableList<Object>> mutableArrayList = FastList.<MutableList<Object>>newList().with(FastList.newList(), FastList.newList(), FastList.newList(), FastList.newList()).with(FastList.newList(), FastList.newList(), FastList.newList(), FastList.newList());
List<List<Object>> arrayList = new ArrayList<>();
Interval.oneTo(8).forEach(Procedures.cast(object -> arrayList.add(new ArrayList<>())));
ByteArrayOutputStream stream2 = SerializeTestHelper.getByteArrayOutputStream(arrayList);
Assert.assertEquals(194L, stream2.size());
ByteArrayOutputStream stream1 = SerializeTestHelper.getByteArrayOutputStream(mutableArrayList);
Assert.assertEquals(182L, stream1.size());
}
Aggregations