Search in sources :

Example 1 with ConcurrentHashMap

use of org.eclipse.collections.impl.map.mutable.ConcurrentHashMap 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);
    }
}
Also used : Arrays(java.util.Arrays) ConcurrentHashMap(org.eclipse.collections.impl.map.mutable.ConcurrentHashMap) Function(org.eclipse.collections.api.block.function.Function) Predicate(org.eclipse.collections.api.block.predicate.Predicate) LoggerFactory(org.slf4j.LoggerFactory) Procedure(org.eclipse.collections.api.block.procedure.Procedure) Verify(org.eclipse.collections.impl.test.Verify) MutableList(org.eclipse.collections.api.list.MutableList) NumberFormat(java.text.NumberFormat) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Function0(org.eclipse.collections.api.block.function.Function0) MutableMap(org.eclipse.collections.api.map.MutableMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) After(org.junit.After) Interval(org.eclipse.collections.impl.list.Interval) ExecutorService(java.util.concurrent.ExecutorService) RandomStringUtils(org.apache.commons.lang.RandomStringUtils) Predicates(org.eclipse.collections.impl.block.factory.Predicates) Before(org.junit.Before) ParallelTests(org.eclipse.collections.impl.ParallelTests) Logger(org.slf4j.Logger) IntegerPredicates(org.eclipse.collections.impl.block.factory.IntegerPredicates) Collection(java.util.Collection) Set(java.util.Set) Procedures(org.eclipse.collections.impl.block.factory.Procedures) Test(org.junit.Test) Iterate(org.eclipse.collections.impl.utility.Iterate) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) List(java.util.List) IntInterval(org.eclipse.collections.impl.list.primitive.IntInterval) Assert(org.junit.Assert) IntProcedure(org.eclipse.collections.api.block.procedure.primitive.IntProcedure) UnifiedSet(org.eclipse.collections.impl.set.mutable.UnifiedSet) ArrayList(java.util.ArrayList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) ConcurrentHashMap(org.eclipse.collections.impl.map.mutable.ConcurrentHashMap)

Example 2 with ConcurrentHashMap

use of org.eclipse.collections.impl.map.mutable.ConcurrentHashMap in project eclipse-collections by eclipse.

the class ConcurrentHashMapTest method newWith.

@Override
public <T> MutableMap<Object, T> newWith(T... elements) {
    Random random = new Random(CURRENT_TIME_MILLIS);
    MutableMap<Object, T> result = new ConcurrentHashMap<>();
    for (T each : elements) {
        assertNull(result.put(random.nextDouble(), each));
    }
    return result;
}
Also used : Random(java.util.Random) ConcurrentHashMap(org.eclipse.collections.impl.map.mutable.ConcurrentHashMap)

Aggregations

ConcurrentHashMap (org.eclipse.collections.impl.map.mutable.ConcurrentHashMap)2 NumberFormat (java.text.NumberFormat)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Random (java.util.Random)1 Set (java.util.Set)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 RandomStringUtils (org.apache.commons.lang.RandomStringUtils)1 Function (org.eclipse.collections.api.block.function.Function)1 Function0 (org.eclipse.collections.api.block.function.Function0)1 Predicate (org.eclipse.collections.api.block.predicate.Predicate)1 Procedure (org.eclipse.collections.api.block.procedure.Procedure)1