Created
May 7, 2014 10:49
-
-
Save sbtourist/51cd5c5081e9399c6356 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 jmh.countdownlatch; | |
import java.util.concurrent.CountDownLatch; | |
import java.util.concurrent.TimeUnit; | |
import org.openjdk.jmh.annotations.BenchmarkMode; | |
import org.openjdk.jmh.annotations.GenerateMicroBenchmark; | |
import org.openjdk.jmh.annotations.Mode; | |
import org.openjdk.jmh.annotations.OutputTimeUnit; | |
import org.openjdk.jmh.annotations.Scope; | |
import org.openjdk.jmh.annotations.Setup; | |
import org.openjdk.jmh.annotations.State; | |
@State(Scope.Thread) | |
@OutputTimeUnit(TimeUnit.MICROSECONDS) | |
@BenchmarkMode(Mode.Throughput) | |
public class CountDownLatchBenchmark | |
{ | |
private CountDownLatch latch; | |
@Setup | |
public void setup() | |
{ | |
latch = new CountDownLatch(1); | |
latch.countDown(); | |
} | |
@GenerateMicroBenchmark | |
public boolean testZeroAwait() throws InterruptedException | |
{ | |
return latch.await(1, TimeUnit.MILLISECONDS); | |
} | |
@GenerateMicroBenchmark | |
public long testGetCount() | |
{ | |
return latch.getCount(); | |
} | |
@GenerateMicroBenchmark | |
public Thread testCurrentThread() | |
{ | |
return Thread.currentThread(); | |
} | |
} | |
Benchmark Mode Samples Mean Mean error Units | |
j.c.CountDownLatchBenchmark.testCurrentThread thrpt 10 382.969 3.820 ops/us | |
j.c.CountDownLatchBenchmark.testGetCount thrpt 10 968.223 41.277 ops/us | |
j.c.CountDownLatchBenchmark.testZeroAwait thrpt 10 491.408 3.645 ops/us |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment