@GenerateMicroBenchmark @Group("Stamped") @GroupThreads(1) public long stWrites() { long stamp; long newValue; stamp = stampedLock.readLock(); try { BlackHole.consumeCPU(consumedCPU); long currentValue = stampedAdder; newValue = currentValue + 1; long writeStamp = stampedLock.tryConvertToWriteLock(stamp); if (writeStamp != 0L) { stamp = writeStamp; stampedAdder = newValue; } else { stampedLock.unlockRead(stamp); stamp = stampedLock.writeLock(); BlackHole.consumeCPU(consumedCPU); currentValue = stampedAdder; newValue = currentValue + 1; stampedAdder = newValue; } } finally { stampedLock.unlock(stamp); } BlackHole.consumeCPU(consumedCPU); return newValue; }
@GenerateMicroBenchmark @Group("Adder") @GroupThreads(1) public void adWrites() { BlackHole.consumeCPU(consumedCPU); longAdder.add(1); BlackHole.consumeCPU(consumedCPU); }
@GenerateMicroBenchmark @Group("Atomic") @GroupThreads(1) public void atWrites() { BlackHole.consumeCPU(consumedCPU); atomicLong.incrementAndGet(); BlackHole.consumeCPU(consumedCPU); }
@GenerateMicroBenchmark @Group("DirtyVolatile") @GroupThreads(1) public void dvWrites() { BlackHole.consumeCPU(consumedCPU); long currentValue = dirtyVolatileAdder; long newValue = currentValue + 1; dirtyVolatileAdder = newValue; BlackHole.consumeCPU(consumedCPU); // return newValue; }
@GenerateMicroBenchmark @Group("Synchronized") @GroupThreads(1) public void syWrites() { long newValue; synchronized (synchronizedGuard) { BlackHole.consumeCPU(consumedCPU); long currentValue = synchronizedAdder; newValue = currentValue + 1; synchronizedAdder = newValue; } BlackHole.consumeCPU(consumedCPU); // return newValue; }
@GenerateMicroBenchmark @Group("Adder") @GroupThreads(1) public long adReads() { BlackHole.consumeCPU(consumedCPU); return longAdder.sum(); }
@GenerateMicroBenchmark @Group("Atomic") @GroupThreads(1) public long atReads() { BlackHole.consumeCPU(consumedCPU); return atomicLong.get(); }
@GenerateMicroBenchmark @Group("DirtyVolatile") @GroupThreads(1) public long dvReads() { BlackHole.consumeCPU(consumedCPU); long currentValue = dirtyVolatileAdder; return currentValue; }
@GenerateMicroBenchmark @Group("ReentrantReadWriteLock") @GroupThreads(1) public void rrwlWrites() { long newValue; try { reentrantReadWriteLock.writeLock().lock(); BlackHole.consumeCPU(consumedCPU); long currentValue = rwlAdder; newValue = currentValue + 1; rwlAdder = newValue; } finally { reentrantReadWriteLock.writeLock().unlock(); } BlackHole.consumeCPU(consumedCPU); // return newValue; }
@GenerateMicroBenchmark @Group("Synchronized") @GroupThreads(1) public long syReads() { synchronized (synchronizedGuard) { BlackHole.consumeCPU(consumedCPU); return synchronizedAdder; } }
@GenerateMicroBenchmark @Group("Stamped") @GroupThreads(1) public long stReads() { long stamp; long currentValue; stamp = stampedLock.tryOptimisticRead(); BlackHole.consumeCPU(consumedCPU); currentValue = stampedAdder; if (!stampedLock.validate(stamp)) { stamp = stampedLock.readLock(); try { BlackHole.consumeCPU(consumedCPU); currentValue = stampedAdder; } finally { stampedLock.unlockRead(stamp); } } return currentValue; }
@GenerateMicroBenchmark @Group("ReentrantReadWriteLock") @GroupThreads(1) public long rrwlReads() { try { reentrantReadWriteLock.readLock().lock(); BlackHole.consumeCPU(consumedCPU); return rwlAdder; } finally { reentrantReadWriteLock.readLock().unlock(); } }
@GenerateMicroBenchmark public void consume_0256() { BlackHole.consumeCPU(256); }
@GenerateMicroBenchmark @OutputTimeUnit(TimeUnit.SECONDS) public void actionLabel(BlackHole bh) throws Exception { bh.consume(parse(STR_ACTION_LABEL_BYTES)); }
@GenerateMicroBenchmark public void consume_0064() { BlackHole.consumeCPU(64); }
@GenerateMicroBenchmark @OutputTimeUnit(TimeUnit.SECONDS) public void citmCatalog(BlackHole bh) throws Exception { bh.consume(parse(STR_CITM_CATALOG_BYTES)); }
@GenerateMicroBenchmark public void consume_0128() { BlackHole.consumeCPU(128); }
@GenerateMicroBenchmark public void consume_0512() { BlackHole.consumeCPU(512); }
@GenerateMicroBenchmark public void consume_0001() { BlackHole.consumeCPU(1); }
@GenerateMicroBenchmark @OutputTimeUnit(TimeUnit.SECONDS) public void widget(BlackHole bh) throws Exception { bh.consume(parse(STR_WIDGET_BYTES)); }
@GenerateMicroBenchmark @OutputTimeUnit(TimeUnit.SECONDS) public void small(BlackHole bh) throws Exception { bh.consume(parse(STR_SMALL_BYTES)); }
@GenerateMicroBenchmark @OutputTimeUnit(TimeUnit.SECONDS) public void medium(BlackHole bh) throws Exception { bh.consume(parse(STR_MEDIUM_BYTES)); }
@GenerateMicroBenchmark public void commonsmath(BlackHole hole) { for (int i = 0; i < data.length - 1; i++) hole.consume(FastMath.exp(data[i])); }
@GenerateMicroBenchmark public void consume_1024() { BlackHole.consumeCPU(1024); }