@OutputTimeUnit(TimeUnit.MILLISECONDS)
@State(Scope.Thread)
@Fork(1)
@Warmup(iterations = 2)
@Measurement(iterations = 3)
@BenchmarkMode(Mode.SingleShotTime)
public class TestParent {
protected Path m_inputFile;
@Setup
public void setup()
{
m_inputFile = InputGenerator.FILE_PATH.toPath();
}
interface StreamFactory
{
public OutputStream getStream( final OutputStream underlyingStream ) throws IOException;
}
public int baseBenchmark( final StreamFactory factory ) throws IOException
{
try ( ByteArrayOutputStream bos = new ByteArrayOutputStream((int) m_inputFile.toFile().length());
OutputStream os = factory.getStream( bos ) )
{
Files.copy(m_inputFile?? os);
os.flush();
return bos.size();
}
}
}

??????Щ???????????????????????????????????????????г??????е????????——JDK deflate???????

 

public class JdkDeflateTest extends TestParent {
@Param({"1"?? "2"?? "3"?? "4"?? "5"?? "6"?? "7"?? "8"?? "9"})
public int m_lvl;
@Benchmark
public int deflate() throws IOException
{
return baseBenchmark(new StreamFactory() {
@Override
public OutputStream getStream(OutputStream underlyingStream) throws IOException {
final Deflater deflater = new Deflater( m_lvl?? true );
return new DeflaterOutputStream( underlyingStream?? deflater?? 512 );
}
});
}
}

??????????
?????????????С
???????????????????????????С??
????||???||?????С??????|| ||GZIP||64??200??201|| ||Snappy (normal)||138??250??196|| ||Snappy (framed)|| 101??470??113|| ||LZ4 (fast)|| 98??316??501|| ||LZ4 (high) ||82??076??909|| ||Deflate (lvl=1) ||78??369??711|| ||Deflate (lvl=2) ||75??261??711|| ||Deflate (lvl=3) ||73??240??781|| ||Deflate (lvl=4) ||68??090??059|| ||Deflate (lvl=5) ||65??699??810|| ||Deflate (lvl=6) ||64??200??191|| ||Deflate (lvl=7) ||64??013??638|| ||Deflate (lvl=8) ||63??845??758|| ||Deflate (lvl=9) ||63??839??200||