Created
August 18, 2017 20:50
-
-
Save akarnokd/c0d606bd7e29d143ee82f2026898dbb5 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.reactive4javaflow; | |
import hu.akarnokd.reactive4javaflow.impl.VH; | |
import org.openjdk.jmh.annotations.*; | |
import java.lang.invoke.*; | |
import java.util.concurrent.TimeUnit; | |
/** | |
* Example benchmark. Run from command line as | |
* <br> | |
* gradle jmh -Pjmh="VolatilePerf" | |
*/ | |
@BenchmarkMode(Mode.Throughput) | |
@Warmup(iterations = 5) | |
@Measurement(iterations = 5, time = 5, timeUnit = TimeUnit.SECONDS) | |
@OutputTimeUnit(TimeUnit.SECONDS) | |
@Fork(value = 1) | |
@State(Scope.Thread) | |
public class VolatilePerf { | |
Object ref; | |
static final VarHandle REF = VH.find(MethodHandles.lookup(), VolatilePerf.class, "ref", Object.class); | |
int[] value = new int[512]; | |
static final VarHandle VALUE = MethodHandles.arrayElementVarHandle(int[].class); | |
@Benchmark | |
public void setRelease() { | |
REF.setRelease(this, this); | |
} | |
@Benchmark | |
public void setVolatile() { | |
REF.setVolatile(this, this); | |
} | |
@Benchmark | |
public void getAndSet() { | |
REF.getAndSet(this, this); | |
} | |
@Benchmark | |
public void getAndAdd() { | |
VALUE.getAndAdd(value, 256, 0); | |
} | |
@Benchmark | |
public void releaseGetAndAdd() { | |
REF.setRelease(this, this); | |
VALUE.getAndAdd(value, 256, 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment