Skip to content

Instantly share code, notes, and snippets.

@darekmydlarz
Last active February 13, 2019 08:39
Show Gist options
  • Save darekmydlarz/ec4bae1b1dbb3e105ee4acc06e32e1ac to your computer and use it in GitHub Desktop.
Save darekmydlarz/ec4bae1b1dbb3e105ee4acc06e32e1ac to your computer and use it in GitHub Desktop.
LongAdder Benchmarks

Wyniki

BenchmarkRareReads:

Benchmark               Mode  Cnt       Score      Error  Units
Benchmarks.atomicLong  thrpt   20   39927.173 ± 3303.513  ops/s
Benchmarks.longAdder   thrpt   20  232363.221 ± 8054.883  ops/s

BenchmarkFrequentReads:

Benchmarks.atomicLong  thrpt   20  37728.593 ±  639.109  ops/s
Benchmarks.longAdder   thrpt   20  42800.584 ± 2916.690  ops/s
public class Benchmarks {
private static int LOOPS = 1_000;
@Benchmark
@Fork(value = 1, warmups = 2)
@GroupThreads(100)
public void atomicLong(Counters counters, Blackhole blackhole) {
for (int i = 0; i < LOOPS; ++i) {
blackhole.consume(counters.atomicCounter.incrementAndGet());
}
}
@Benchmark
@Fork(value = 1, warmups = 2)
@GroupThreads(100)
public void longAdder(Counters counters, Blackhole blackhole) {
for (int i = 0; i < LOOPS; ++i) {
counters.adderCounter.increment();
blackhole.consume(counters.adderCounter.sum());
}
}
}
public class Benchmarks {
private static int LOOPS = 1_000;
@Benchmark
@Fork(value = 1, warmups = 2)
@GroupThreads(100)
public void atomicLong(Counters counters, Blackhole blackhole) {
for (int i = 0; i < LOOPS; ++i) {
counters.atomicCounter.incrementAndGet();
}
blackhole.consume(counters.atomicCounter.get());
}
@Benchmark
@Fork(value = 1, warmups = 2)
@GroupThreads(100)
public void longAdder(Counters counters, Blackhole blackhole) {
for (int i = 0; i < LOOPS; ++i) {
counters.adderCounter.increment();
}
blackhole.consume(counters.adderCounter.sum());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment