压缩算法输入字节及压缩率测试,比较算法有 jdk Inflate, google snappy.
输入数据共两份:
1. RandomStringUtils.randomAlphabetic(count) 生成的随机字母
2. 正常的英文文章
测试结果说明:
input.length=输入大小 output.length=输出大小 Income.length:节省的大小 income.percent:压缩率%
------------Inflate,input by RandomStringUtils.randomAlphabetic(count) -------------- input.length=1 output.length=2 Income.length:-1 income.percent:-100% input.length=101 output.length=97 Income.length:4 income.percent:3% input.length=201 output.length=170 Income.length:31 income.percent:15% input.length=301 output.length=239 Income.length:62 income.percent:20% input.length=401 output.length=310 Income.length:91 income.percent:22% input.length=501 output.length=382 Income.length:119 income.percent:23% input.length=601 output.length=456 Income.length:145 income.percent:24% input.length=701 output.length=528 Income.length:173 income.percent:24% input.length=801 output.length=598 Income.length:203 income.percent:25% input.length=901 output.length=673 Income.length:228 income.percent:25% input.length=1001 output.length=745 Income.length:256 income.percent:25% input.length=1101 output.length=816 Income.length:285 income.percent:25% input.length=1201 output.length=887 Income.length:314 income.percent:26% input.length=1301 output.length=960 Income.length:341 income.percent:26% input.length=1401 output.length=1025 Income.length:376 income.percent:26% input.length=1501 output.length=1103 Income.length:398 income.percent:26% input.length=1601 output.length=1175 Income.length:426 income.percent:26% input.length=1701 output.length=1249 Income.length:452 income.percent:26% input.length=1801 output.length=1323 Income.length:478 income.percent:26% input.length=1901 output.length=1396 Income.length:505 income.percent:26% input.length=2001 output.length=1469 Income.length:532 income.percent:26% ------------Inflate,input by normal english article-------------- input.length=1 output.length=2 Income.length:-1 income.percent:-100% input.length=101 output.length=79 Income.length:22 income.percent:21% input.length=201 output.length=139 Income.length:62 income.percent:30% input.length=301 output.length=196 Income.length:105 income.percent:34% input.length=401 output.length=249 Income.length:152 income.percent:37% input.length=501 output.length=299 Income.length:202 income.percent:40% input.length=601 output.length=349 Income.length:252 income.percent:41% input.length=701 output.length=403 Income.length:298 income.percent:42% input.length=801 output.length=446 Income.length:355 income.percent:44% input.length=901 output.length=494 Income.length:407 income.percent:45% input.length=1001 output.length=532 Income.length:469 income.percent:46% input.length=1101 output.length=586 Income.length:515 income.percent:46% input.length=1201 output.length=640 Income.length:561 income.percent:46% input.length=1301 output.length=680 Income.length:621 income.percent:47% input.length=1401 output.length=723 Income.length:678 income.percent:48% input.length=1501 output.length=769 Income.length:732 income.percent:48% input.length=1601 output.length=824 Income.length:777 income.percent:48% input.length=1701 output.length=868 Income.length:833 income.percent:48% input.length=1801 output.length=912 Income.length:889 income.percent:49% input.length=1901 output.length=942 Income.length:959 income.percent:50% input.length=2001 output.length=981 Income.length:1020 income.percent:50% Google Snappy压缩率测试 ------------Snappy,input by RandomStringUtils.randomAlphabetic(count) -------------- input.length=1 output.length=3 Income.length:-2 income.percent:-200% input.length=101 output.length=104 Income.length:-3 income.percent:-2% input.length=201 output.length=205 Income.length:-4 income.percent:-1% input.length=301 output.length=306 Income.length:-5 income.percent:-1% input.length=401 output.length=406 Income.length:-5 income.percent:-1% input.length=501 output.length=506 Income.length:-5 income.percent:0% input.length=601 output.length=606 Income.length:-5 income.percent:0% input.length=701 output.length=706 Income.length:-5 income.percent:0% input.length=801 output.length=806 Income.length:-5 income.percent:0% input.length=901 output.length=906 Income.length:-5 income.percent:0% input.length=1001 output.length=1006 Income.length:-5 income.percent:0% input.length=1101 output.length=1106 Income.length:-5 income.percent:0% input.length=1201 output.length=1206 Income.length:-5 income.percent:0% input.length=1301 output.length=1306 Income.length:-5 income.percent:0% input.length=1401 output.length=1406 Income.length:-5 income.percent:0% input.length=1501 output.length=1506 Income.length:-5 income.percent:0% input.length=1601 output.length=1606 Income.length:-5 income.percent:0% input.length=1701 output.length=1706 Income.length:-5 income.percent:0% input.length=1801 output.length=1806 Income.length:-5 income.percent:0% input.length=1901 output.length=1906 Income.length:-5 income.percent:0% input.length=2001 output.length=2006 Income.length:-5 income.percent:0% ------------Snappy,input by normal english article-------------- input.length=1 output.length=3 Income.length:-2 income.percent:-200% input.length=101 output.length=101 Income.length:0 income.percent:0% input.length=201 output.length=202 Income.length:-1 income.percent:0% input.length=301 output.length=285 Income.length:16 income.percent:5% input.length=401 output.length=362 Income.length:39 income.percent:9% input.length=501 output.length=439 Income.length:62 income.percent:12% input.length=601 output.length=510 Income.length:91 income.percent:15% input.length=701 output.length=601 Income.length:100 income.percent:14% input.length=801 output.length=664 Income.length:137 income.percent:17% input.length=901 output.length=741 Income.length:160 income.percent:17% input.length=1001 output.length=799 Income.length:202 income.percent:20% input.length=1101 output.length=864 Income.length:237 income.percent:21% input.length=1201 output.length=933 Income.length:268 income.percent:22% input.length=1301 output.length=994 Income.length:307 income.percent:23% input.length=1401 output.length=1047 Income.length:354 income.percent:25% input.length=1501 output.length=1114 Income.length:387 income.percent:25% input.length=1601 output.length=1194 Income.length:407 income.percent:25% input.length=1701 output.length=1259 Income.length:442 income.percent:25% input.length=1801 output.length=1331 Income.length:470 income.percent:26% input.length=1901 output.length=1374 Income.length:527 income.percent:27% input.length=2001 output.length=1429 Income.length:572 income.percent:28% input.length=2101 output.length=1491 Income.length:610 income.percent:29% input.length=2201 output.length=1567 Income.length:634 income.percent:28% input.length=2301 output.length=1626 Income.length:675 income.percent:29% input.length=2401 output.length=1677 Income.length:724 income.percent:30% input.length=2501 output.length=1748 Income.length:753 income.percent:30% input.length=2601 output.length=1810 Income.length:791 income.percent:30% input.length=2701 output.length=1886 Income.length:815 income.percent:30% input.length=2801 output.length=1950 Income.length:851 income.percent:30% input.length=2901 output.length=2020 Income.length:881 income.percent:30% input.length=3001 output.length=2087 Income.length:914 income.percent:30%
测试结论:
通过Inflate压缩,至少需要200-300字节以上才有较大收益
Snappy至少需要800字节以上开始压缩才有较大收益