Search in sources :

Example 16 with LongAdder

use of java8.util.concurrent.atomic.LongAdder in project streamsupport by stefan-zobel.

the class SplittableRandomTest method testLongsCount.

/**
 * A parallel sized stream of longs generates the given number of values
 */
public void testLongsCount() {
    final LongAdder counter = new LongAdder();
    SplittableRandom r = new SplittableRandom();
    long size = 0;
    for (int reps = 0; reps < REPS; ++reps) {
        counter.reset();
        r.longs(size).parallel().forEach(new LongConsumer() {

            @Override
            public void accept(long x) {
                counter.increment();
            }
        });
        assertEquals(counter.sum(), size);
        size += 524959;
    }
}
Also used : LongConsumer(java8.util.function.LongConsumer) LongAdder(java8.util.concurrent.atomic.LongAdder) SplittableRandom(java8.util.SplittableRandom)

Example 17 with LongAdder

use of java8.util.concurrent.atomic.LongAdder in project streamsupport by stefan-zobel.

the class SplittableRandomTest method testUnsizedIntsCountSeq.

/**
 * A sequential unsized stream of ints generates at least 100 values
 */
public void testUnsizedIntsCountSeq() {
    final LongAdder counter = new LongAdder();
    SplittableRandom r = new SplittableRandom();
    long size = 100;
    r.ints().limit(size).forEach(new IntConsumer() {

        @Override
        public void accept(int x) {
            counter.increment();
        }
    });
    assertEquals(counter.sum(), size);
}
Also used : LongAdder(java8.util.concurrent.atomic.LongAdder) SplittableRandom(java8.util.SplittableRandom) IntConsumer(java8.util.function.IntConsumer)

Example 18 with LongAdder

use of java8.util.concurrent.atomic.LongAdder in project streamsupport by stefan-zobel.

the class SplittableRandomTest method testUnsizedLongsCount.

/**
 * A parallel unsized stream of longs generates at least 100 values
 */
public void testUnsizedLongsCount() {
    final LongAdder counter = new LongAdder();
    SplittableRandom r = new SplittableRandom();
    long size = 100;
    r.longs().limit(size).parallel().forEach(new LongConsumer() {

        @Override
        public void accept(long x) {
            counter.increment();
        }
    });
    assertEquals(counter.sum(), size);
}
Also used : LongConsumer(java8.util.function.LongConsumer) LongAdder(java8.util.concurrent.atomic.LongAdder) SplittableRandom(java8.util.SplittableRandom)

Example 19 with LongAdder

use of java8.util.concurrent.atomic.LongAdder in project streamsupport by stefan-zobel.

the class ThreadLocalRandomTest method testUnsizedDoublesCount.

/**
 * A parallel unsized stream of doubles generates at least 100 values
 */
public void testUnsizedDoublesCount() {
    LongAdder counter = new LongAdder();
    ThreadLocalRandom r = ThreadLocalRandom.current();
    long size = 100;
    r.doubles().limit(size).parallel().forEach(x -> {
        counter.increment();
    });
    assertEquals(counter.sum(), size);
}
Also used : LongAdder(java8.util.concurrent.atomic.LongAdder) ThreadLocalRandom(java8.util.concurrent.ThreadLocalRandom)

Example 20 with LongAdder

use of java8.util.concurrent.atomic.LongAdder in project streamsupport by stefan-zobel.

the class ThreadLocalRandomTest method testUnsizedDoublesCountSeq.

/**
 * A sequential unsized stream of doubles generates at least 100 values
 */
public void testUnsizedDoublesCountSeq() {
    LongAdder counter = new LongAdder();
    ThreadLocalRandom r = ThreadLocalRandom.current();
    long size = 100;
    r.doubles().limit(size).forEach(x -> {
        counter.increment();
    });
    assertEquals(counter.sum(), size);
}
Also used : LongAdder(java8.util.concurrent.atomic.LongAdder) ThreadLocalRandom(java8.util.concurrent.ThreadLocalRandom)

Aggregations

LongAdder (java8.util.concurrent.atomic.LongAdder)50 SplittableRandom (java8.util.SplittableRandom)18 ThreadLocalRandom (java8.util.concurrent.ThreadLocalRandom)18 DoubleConsumer (java8.util.function.DoubleConsumer)3 IntConsumer (java8.util.function.IntConsumer)3 LongConsumer (java8.util.function.LongConsumer)3 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 ExecutorService (java.util.concurrent.ExecutorService)1 Phaser (java8.util.concurrent.Phaser)1