Created
October 21, 2017 18:16
-
-
Save akarnokd/0dd5867c18aa3fd111377019207ea039 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hu.akarnokd.atomics; | |
import java.util.concurrent.TimeUnit; | |
import java.util.concurrent.atomic.AtomicReference; | |
import org.openjdk.jmh.annotations.*; | |
import org.openjdk.jmh.infra.Blackhole; | |
@BenchmarkMode(Mode.Throughput) | |
@Warmup(iterations = 5) | |
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) | |
@OutputTimeUnit(TimeUnit.SECONDS) | |
@Fork(value = 1) | |
@State(Scope.Thread) | |
public class TerminalAtomics { | |
final AtomicReference<Object> ref = new AtomicReference<>(); | |
final Object o = new Object(); | |
void getGetAndSet(Blackhole bh) { | |
Object o = ref.get(); | |
if (o != null) { | |
o = ref.getAndSet(null); | |
if (o != null) { | |
bh.consume(o); | |
} | |
} | |
} | |
void getAndSet(Blackhole bh) { | |
Object o = ref.getAndSet(null); | |
if (o != null) { | |
bh.consume(o); | |
} | |
} | |
@Benchmark | |
public void GGASx1(Blackhole bh) { | |
ref.lazySet(o); | |
getGetAndSet(bh); | |
} | |
@Benchmark | |
public void GGASx2(Blackhole bh) { | |
ref.lazySet(o); | |
getGetAndSet(bh); | |
getGetAndSet(bh); | |
} | |
@Benchmark | |
public void GGASx3(Blackhole bh) { | |
ref.lazySet(o); | |
getGetAndSet(bh); | |
getGetAndSet(bh); | |
getGetAndSet(bh); | |
} | |
@Benchmark | |
public void GGASx4(Blackhole bh) { | |
ref.lazySet(o); | |
getGetAndSet(bh); | |
getGetAndSet(bh); | |
getGetAndSet(bh); | |
getGetAndSet(bh); | |
} | |
@Benchmark | |
public void GASx1(Blackhole bh) { | |
ref.lazySet(o); | |
getAndSet(bh); | |
} | |
@Benchmark | |
public void GASx2(Blackhole bh) { | |
ref.lazySet(o); | |
getAndSet(bh); | |
getAndSet(bh); | |
} | |
@Benchmark | |
public void GASx3(Blackhole bh) { | |
ref.lazySet(o); | |
getAndSet(bh); | |
getAndSet(bh); | |
getAndSet(bh); | |
} | |
@Benchmark | |
public void GASx4(Blackhole bh) { | |
ref.lazySet(o); | |
getAndSet(bh); | |
getAndSet(bh); | |
getAndSet(bh); | |
getAndSet(bh); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment