Created
May 10, 2016 21:09
-
-
Save nitsanw/3fc1007f54e136a40a6168e58516f653 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 safepoint.profiling; | |
import java.util.Random; | |
import java.util.concurrent.TimeUnit; | |
import java.util.concurrent.locks.LockSupport; | |
import java.util.zip.Adler32; | |
import java.util.zip.CRC32; | |
import org.openjdk.jmh.annotations.Benchmark; | |
import org.openjdk.jmh.annotations.BenchmarkMode; | |
import org.openjdk.jmh.annotations.Mode; | |
import org.openjdk.jmh.annotations.OutputTimeUnit; | |
import org.openjdk.jmh.annotations.Param; | |
import org.openjdk.jmh.annotations.Scope; | |
import org.openjdk.jmh.annotations.Setup; | |
import org.openjdk.jmh.annotations.State; | |
@BenchmarkMode(Mode.AverageTime) | |
@OutputTimeUnit(TimeUnit.NANOSECONDS) | |
@State(Scope.Thread) | |
public class AgctProfilingFails { | |
@Param("1000") | |
int size; | |
CRC32 crc = new CRC32(); | |
Adler32 adler = new Adler32(); | |
byte[] buffer; | |
byte[] dst; | |
boolean result; | |
@Setup | |
public final void setup() { | |
Random randomGenerator = new Random(666); | |
buffer = new byte[size]; | |
randomGenerator.nextBytes(buffer); | |
dst = new byte[size]; | |
} | |
@Benchmark | |
public int systemArrayCopy() { | |
System.arraycopy(buffer, 0, dst, 0, buffer.length); | |
return dst[buffer.length-1]; | |
} | |
@Benchmark | |
public long adler32(){ | |
adler.update(buffer); | |
return adler.getValue(); | |
} | |
@Benchmark | |
public long crc32(){ | |
crc.update(buffer); | |
return crc.getValue(); | |
} | |
@Benchmark | |
public long adler32AndPark() { | |
adler.update(buffer); | |
LockSupport.parkNanos(1); | |
return adler.getValue(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment