Performance comparison of Java's own compression methods

The commonly used compression method in Java is gzip. Its performance is much better than another zip compression method. I took the time to write a program to verify it.

 

Compression comparisons are performed with byte strings of the following lengths, respectively

int [] intArr = {1, 10, 50, 100, 200, 300, 500, 700, 900, 1000, 2000, 5000, 10000, 100000, 1000000};

 The test results are as follows

// Compression size analysis
origin=1,gzip=21,zip=123
origin=10,gzip=30,zip=132
origin=50,gzip=70,zip=172
origin=100,gzip=119,zip=221
origin=200,gzip=194,zip=296
origin=300,gzip=269,zip=371
origin=500,gzip=420,zip=522
origin=700,gzip=568,zip=670
origin=900,gzip=719,zip=821
origin=1000,gzip=790,zip=892
origin=2000,gzip=1535,zip=1637
origin=5000,gzip=3787,zip=3889
origin=10000,gzip=7540,zip=7642
origin=100000,gzip=75205,zip=75307
origin=1000000,gzip=752046,zip=752148

 

// Compression analysis
origin=1,gzip=2100.00%,zip=12300.00%
origin=10,gzip=300.00%,zip=1320.00%
origin=50,gzip=140.00%,zip=344.00%
origin=100,gzip=119.00%,zip=221.00%
origin=200,gzip=97.00%,zip=148.00%
origin=300,gzip=89.67%,zip=123.67%
origin=500,gzip=84.00%,zip=104.40%
origin=700,gzip=81.14%,zip=95.71%
origin=900,gzip=79.89%,zip=91.22%
origin=1000,gzip=79.00%,zip=89.20%
origin=2000,gzip=76.75%,zip=81.85%
origin=5000,gzip=75.74%,zip=77.78%
origin=10000,gzip=75.40%,zip=76.42%
origin=100000,gzip=75.21%,zip=75.31%
origin=1000000,gzip=75.20%,zip=75.21%

 

// Compression time analysis
origin=1,gzip=58ms,zip=2ms
origin=10,gzip=0ms,zip=0ms
origin=50,gzip=0ms,zip=0ms
origin=100,gzip=1ms,zip=0ms
origin=200,gzip=0ms,zip=0ms
origin=300,gzip=0ms,zip=1ms
origin=500,gzip=0ms,zip=0ms
origin=700,gzip=0ms,zip=1ms
origin=900,gzip=0ms,zip=0ms
origin=1000,gzip=0ms,zip=1ms
origin=2000,gzip=0ms,zip=0ms
origin=5000,gzip=1ms,zip=0ms
origin=10000,gzip=1ms,zip=0ms
origin=100000,gzip=5ms,zip=5ms
origin=1000000,gzip=52ms,zip=55ms

 

 Analysis and Conclusion

1) If the number of bytes of the content is too small, it is not suitable for compression, and the compressed content will be larger.

2) The compression rate of gzip is greater than that of zip. As the number of bytes increases, the compression rate of zip is close to that of gzip.

3) There is little difference between gzip and zip compression time

Therefore, in actual use, gzip is mostly used.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326222456&siteId=291194637