Created
January 30, 2015 07:46
-
-
Save akarnokd/6071deb98e92323f3672 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 rx.internal; | |
import java.util.Deque; | |
import java.util.concurrent.*; | |
import org.openjdk.jmh.annotations.*; | |
import org.openjdk.jmh.infra.Control; | |
import rx.internal.util.ArrayBasedLockFreeStack; | |
/** | |
* Benchmark lock free stack. | |
* <p> | |
* gradlew benchmarks "-Pjmh=-f 1 -tu s -bm thrpt -wi 5 -i 5 -r 1 .*LockfreeStackPerf.*" | |
* <p> | |
* gradlew benchmarks "-Pjmh=-f 1 -tu ns -bm avgt -wi 5 -i 5 -r 1 .*LockfreeStackPerf.*" | |
*/ | |
@BenchmarkMode(Mode.Throughput) | |
@OutputTimeUnit(TimeUnit.SECONDS) | |
@Threads(2) | |
@State(Scope.Group) | |
public class LockfreeStackPerf { | |
final Integer ONE = new Integer(1); | |
final Integer TWO = new Integer(2); | |
final ArrayBasedLockFreeStack<Integer> stack = new ArrayBasedLockFreeStack<Integer>(8); | |
final Deque<Integer> stack2 = new ConcurrentLinkedDeque<Integer>(); | |
@Param({"100000", "1000000"}) | |
int loop; | |
@Benchmark | |
@Group("tpt") | |
@GroupThreads(1) | |
public void offer(Control cnt) { | |
int i = loop; | |
while (i-- > 0) { | |
stack2.push(ONE); | |
stack2.pop(); | |
} | |
} | |
@Benchmark | |
@Group("tpt") | |
@GroupThreads(1) | |
public void poll(Control cnt) { | |
int i = loop; | |
while (i-- > 0) { | |
stack2.push(TWO); | |
stack2.pop(); | |
} | |
} | |
@Benchmark | |
@Group("tpt2") | |
@GroupThreads(1) | |
public void offer2(Control cnt) { | |
int i = loop; | |
while (i-- > 0) { | |
stack2.push(ONE); | |
stack2.pop(); | |
} | |
} | |
@Benchmark | |
@Group("tpt2") | |
@GroupThreads(1) | |
public void poll2(Control cnt) { | |
int i = loop; | |
while (i-- > 0) { | |
stack2.push(TWO); | |
stack2.pop(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment