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
Sample files for blogs |
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
@Generated("org.openjdk.jmh.processor.internal.GenerateMicroBenchmarkProcessor") | |
public final class JMHSample_01_HelloWorld { | |
@Threads(1) | |
public Result wellHelloThere_Throughput(Loop loop) throws Throwable { | |
if (!threadId_inited) { | |
threadId = threadSelector.getAndIncrement(); | |
threadId_inited = true; | |
} |
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
@GenerateMicroBenchmark | |
public void baseline() { | |
// do nothing, this is a baseline | |
} | |
@GenerateMicroBenchmark | |
public void measureWrong() { | |
// This is wrong: result is not used, and the entire computation is optimized out. | |
Math.log(x); | |
} |
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
private double x = Math.PI; | |
@GenerateMicroBenchmark | |
public void baseline() { | |
// do nothing, this is a baseline | |
} | |
@GenerateMicroBenchmark | |
public double measureWrong() { | |
// This is wrong: the result is provably the same, optimized out. |
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
@CompilerControl(CompilerControl.Mode.DONT_INLINE) | |
public void target_dontInline() { | |
// this method was intentionally left blank | |
} | |
@CompilerControl(CompilerControl.Mode.INLINE) | |
public void target_inline() { | |
// this method was intentionally left blank | |
} |
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
private AtomicInteger counter; | |
@Setup | |
public void up() { | |
counter = new AtomicInteger(); | |
} | |
@GenerateMicroBenchmark | |
@Group("g") | |
@Threads(8) |
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
private ReentrantLock lock = new ReentrantLock(); | |
private Condition dataChanged = lock.newCondition(); | |
@Override | |
public void block() throws InterruptedException { | |
try { | |
lock.lock(); | |
dataChanged.await(); | |
} finally { | |
lock.unlock(); |
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
private AtomicReferenceArray<Thread> consumerWorker; | |
@Override | |
public void block() throws InterruptedException { | |
boolean parked=false; | |
for(int index=0;index<consumer;index++) | |
{ | |
if(consumerWorker.get(index)==null && consumerWorker.compareAndSet(index, null, Thread.currentThread())) |
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
if (isRunning(c) && workQueue.offer(command)) { | |
int recheck = ctl.get(); | |
if (! isRunning(recheck) && remove(command)) | |
reject(command); | |
else if (workerCountOf(recheck) == 0) | |
addWorker(null, false); | |
} | |
else if (!addWorker(command, false)) | |
reject(command); |
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
while(!queue.isEmpty()) | |
{ | |
T element = queue.take(); | |
//Process element. | |
} |
OlderNewer